Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 LL lt,rt; 18 LL test(LL x){ 19 int d[20],i = 0,j,sum = 0; 20 LL y = x; 21 while(x){d[i++] = x%10; x /= 10;} 22 for(j = 0; j < i; j++){ 23 if(j&1)sum -= d[j]; 24 else sum += d[j]; 25 } 26 if(sum != 3) return y; 27 return -1; 28 } 29 int main() { 30 int t; 31 LL tst; 32 scanf("%d",&t); 33 while(t--){ 34 scanf("%I64d %I64d",<,&rt); 35 bool flag = false; 36 for(LL i = lt/11+1; i*11+3 <= rt; i++){ 37 tst = test(i*11+3); 38 if(tst > 0) {flag = true;break;} 39 } 40 if(flag) printf("%I64d\n",tst); 41 else puts("-1"); 42 } 43 return 0; 44 }
原文:http://www.cnblogs.com/crackpotisback/p/3918225.html