暴力就行了;
代码:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> //#include<windows.h> using namespace std; #define mem(x,y) memset(x,y,sizeof(x)) #define SI(x) scanf("%d",&x) #define PI(x) printf("%d",x) #define P_ printf(" ") const int INF=0x3f3f3f3f; typedef long long LL; int main(){ int N; SI(N); bool flot=false; for(int i=10000;i<1000000;i++){ int cur=0; int temp=i; int a,b,c,d,e,f,t=0; //bool yy=true; while(temp){ cur+=temp%10; t++; if(t==1)a=temp%10; if(t==2)b=temp%10; if(t==3)c=temp%10; if(t==4)d=temp%10; if(t==5)e=temp%10; if(t==6)f=temp%10; temp/=10; } if(t==5){ if(a!=e||b!=d)continue; } if(t==6){ if(a!=f||b!=e||c!=d)continue; } //if(i==189998)printf("%d %d %d\n",a,b,c); //if(!yy)continue; if(cur==N){ printf("%d\n",i); // system("pause"); flot=true; } } if(!flot)puts("-1"); return 0; }
原文:http://www.cnblogs.com/handsomecui/p/5117394.html