代码改变世界

1797. Do solve it directly

2011-05-16 19:34  Min·zc  阅读(138)  评论(0编辑  收藏  举报
 1 #include <iostream>
 2 using namespace std;
 3 int d;
 4 int x,y;
 5 void run(int a,int b)
 6 {
 7         if(a<=0||b<=0)
 8                 return ;
 9         if(d==0)
10                 y++;
11         else if(d==1)
12                 x++;
13         else if(d==2)
14                 y--;
15         else
16                 x--;
17         run(a-b,b);
18         d=(d+1)%4;
19         run(b-a,a);
20         return ;
21 }
22 int main()
23 {
24         int t;
25         cin>>t;
26         while(t--)
27         {
28                 int a,b;
29                 cin>>a>>b;
30                 x=y=0;
31                 d=0;
32                 run(a,b);
33                 cout<<x<<" "<<y<<endl;
34         }       
35 }