题目链接: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 ",ans); 32 else printf("No Number "); 33 } 34 return 0; 35 }