(HDU)1391 -- Number Steps (数字阶梯)

题目链接:http://vjudge.net/problem/HDU-1391

其实这个题目只要判断x、y是否满足两个表达式之一,然后用找规律出来的公式套x进去就可以了...

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <string>
 7 #include <cstdlib>
 8 
 9 using namespace std;
10 
11 int main()
12 {
13     int t,x,y,ans,flag;
14     scanf("%d",&t);
15     while(t--)
16     {
17         flag=0;
18         scanf("%d %d",&x,&y);
19         if(x==y)
20         {
21             if(x%2==0) ans=2*x;
22             else ans=2*x-1;
23             flag=1;
24         }
25         if(x-2==y)
26         {
27             if((x-2)%2==0) ans=2*x-2;
28             else ans=2*x-3;
29             flag=1;
30         }
31         if(flag) printf("%d\n",ans);
32             else printf("No Number\n");
33     }
34     return 0;
35 }

 

posted @ 2016-12-06 15:52  ACDoge  阅读(210)  评论(0编辑  收藏  举报