Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- long long t;
- cin >> t;
- for(long long i = 1; i <= t; i++){
- long long ycord = 1, xcord = 1, layer = 1, num = 1;
- char move = 'r';
- long long x, y;
- cin >> y >> x;
- while(1){
- cout << "present position : " << ycord << ' ' << xcord << " num : " << num << " layer : " << layer << ' ' << move <<'\n';
- if(xcord == x && ycord == y) break;
- if(move == 'r') xcord++;
- else if(move == 'l') xcord--;
- else if(move == 'u') ycord--;
- else if (move == 'd') ycord++;
- num++;
- if(ycord == 1){
- layer=layer+1;
- if(layer%2==0) move = 'd';
- else move ='r';
- }
- if(xcord == 1){
- layer=layer+1;
- if(layer%2==0) move = 'd';
- else move = 'r';
- }
- if(xcord == ycord){
- if(layer%2==0) move = 'l';
- else move = 'u';
- }
- }
- // cout << num << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement