hdoj 1271 整数对

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1271

解题思路:设所求为 x=a+b*10k+c*10k+1 , 拿走 x 的第 k 位,得到 y=a+c*10k , 则 n=x+y=2*a+b*10k+11*c*10k .

 1 ///////////////////////////////////////////////////////////////////////////
 2 //problem_id: hdoj 1271
 3 //user_id: SCNU20102200088
 4 ///////////////////////////////////////////////////////////////////////////
 5 
 6 #include <algorithm>
 7 #include <iostream>
 8 #include <iterator>
 9 #include <iomanip>
10 #include <cstring>
11 #include <cstdlib>
12 #include <string>
13 #include <vector>
14 #include <cstdio>
15 #include <cctype>
16 #include <cmath>
17 #include <queue>
18 #include <stack>
19 #include <list>
20 #include <set>
21 #include <map>
22 using namespace std;
23 
24 ///////////////////////////////////////////////////////////////////////////
25 typedef long long LL;
26 const double PI=acos(-1.0);
27 
28 const int x4[]={-1,0,1,0};
29 const int y4[]={0,1,0,-1};
30 const int x8[]={-1,-1,0,1,1,1,0,-1};
31 const int y8[]={0,1,1,1,0,-1,-1,-1};
32 
33 typedef int T;
34 T max(T a,T b){ return a>b? a:b; }
35 T min(T a,T b){ return a<b? a:b; }
36 ///////////////////////////////////////////////////////////////////////////
37 
38 ///////////////////////////////////////////////////////////////////////////
39 //Add Code:
40 ///////////////////////////////////////////////////////////////////////////
41 
42 int main(){
43     ///////////////////////////////////////////////////////////////////////
44     //Add code:
45     int n,k,a,b,c;
46     set<int> s;
47     while(scanf("%d",&n)!=EOF){
48         if(n==0) break;
49         s.clear();
50         for(k=1;k<=n;k*=10){
51             c=n/k/11;
52             b=n/k%11;
53             if((b!=0 || c!=0) && b<10){
54                 a=(n-b*k-c*11*k)/2;
55                 if(2*a+b*k+c*11*k==n) s.insert(a+b*k+c*10*k);
56             }
57             b--;
58             if((b!=0 || c!=0) && b>=0){
59                 a=(n-b*k-c*11*k)/2;
60                 if(2*a+b*k+c*11*k==n) s.insert(a+b*k+c*10*k);
61             }
62         }
63         if(s.empty()) printf("No solution.\n");
64         else{
65             set<int>::iterator it=s.begin();
66             printf("%d",*it);
67             while(++it!=s.end()) printf(" %d",*it);
68             printf("\n");
69         }
70     }
71     ///////////////////////////////////////////////////////////////////////
72     return 0;
73 }
74 
75 ///////////////////////////////////////////////////////////////////////////
76 /*
77 Testcase:
78 Input:
79 34
80 152
81 21
82 0
83 Output:
84 27 31 32
85 126 136 139 141
86 No solution.
87 */
88 ///////////////////////////////////////////////////////////////////////////

posted on 2013-08-23 09:45  SCNU20102200088  阅读(189)  评论(0编辑  收藏  举报

导航