- 제목
2-3 Moves
- 조건
time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output
- 문제
You are standing at the point 0 on a coordinate line. Your goal is to reach the point n. In one minute, you can move by 2 or by 3 to the left or to the right (i.e., if your current coordinate is x, it can become x−3, x−2, x+2 or x+3). Note that the new coordinate can become negative.
Your task is to find the minimum number of minutes required to get from the point 0 to the point n.
You have to answer t independent test cases.
- 입력
The first line of the input contains one integer t (1≤t≤10^4) — the number of test cases. Then t lines describing the test cases follow.
The i-th of these lines contains one integer n (1≤n≤10^9) — the goal of the i-th test case.
- 출력
For each test case, print one integer — the minimum number of minutes required to get from the point 0 to the point n for the corresponding test case.
예제 입력1 | 예제 출력1 |
4 1 3 4 12 |
2 1 2 4 |
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define endl '\n'
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc, destination;
cin >> tc;
while(tc--){
cin >> destination;
int cnt;
if(destination % 3 == 0) cout << destination / 3 << endl;
else{
if(destination == 1) cout << 2 << endl;
else{
cout << destination / 3 + 1 << endl;
}
}
}
return 0;
}