Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2109 Accepted Submission(s): 700
34 152 21 0
27 31 32 126 136 139 141 No solution.
思路:
x+y*10^k+10^(k+1)*z+x+z^10^k=N
2*x+(11z+y)*10^k=N
N%10^k=2*x;
w=N/10^k; w=11z+y;z=w/11; y=w%11;
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; const int mm=1100; int x,y,n,ans; int pos,f[mm],ten[11]; void judge(int a,int c,int k) { int z; if(c&1)return; z=ans=c/2;///low x=a/11;///high y=a%11;///erase if(y<10&&y>=0) { ans+=(y+11*x)*ten[k]+ans; if(ans==n&&(x||y))f[pos++]=ans=(x*10+y)*ten[k]+z; } --y; z=ans=(c+ten[k])/2; if(y<10&&y>=0) { ans+=(y+11*x)*ten[k]+ans; if(ans==n&&(x||y))ans=f[pos++]=(y+10*x)*ten[k]+z; } } int main() { ten[0]=1; for(int i=1;i<10;++i) ten[i]=ten[i-1]*10; while(scanf("%d",&n)&&n) { pos=0; for(int i=0;i<=9;++i) { judge(n/ten[i],n%ten[i],i); } sort(f,f+pos); if(!pos){printf("No solution.");printf("\n");continue;} int last=f[0]; printf("%d",f[0]); for(int i=1;i<pos;++i) if(f[i]^last) {printf(" %d",f[i]); last=f[i]; } printf("\n"); } return 0; }