# POJ1663（找规律）

View Code
1 #include<iostream>
2 #include<cstdio>
3 using namespace std;
4 int an[3000][3000];
5 int main()
6 {
7     int i,k=0,n,x,y;
8     for(i=0;i<=5000;i=i+4)
9     {
10         an[i-2*k][i-2*k]=i;
11         an[i+1-2*k][i+1-2*k]=(i+1);
12         an[i+2-2*k][i-2*k]=(i+2);
13         an[i+3-2*k][i+1-2*k]=(i+3);
14         k++;
15     }
16     scanf("%d",&n);
17     while(n--)
18     {
19         scanf("%d %d",&x,&y);
20         if(x!=0&&y!=0&&an[x][y]==0) printf("No Number\n");
21         else printf("%d\n",an[x][y]);
22     }
23     return 0;
24 }

View Code
1 #include<iostream>
2 #include<cstdio>
3 using namespace std;
4 int main()
5 {
6     int n,x,y;
7     scanf("%d",&n);
8     while(n--)
9     {
10         scanf("%d %d",&x,&y);
11         if(x==y)
12         {
13             if(x%2==1)  printf("%d\n",2*x-1);
14             else  printf("%d\n",2*x);
15         }
16         else if(x==y+2)
17         {
18             if(x%2==1) printf("%d\n",x+y-1);
19             else printf("%d\n",x+y);
20         }
21         else printf("No Number\n");
22     }
23     return 0;
24 }

posted @ 2012-05-07 11:50  笑巧  阅读(361)  评论(0编辑  收藏  举报