对于这种需要一遍遍枚举求解的,打表可以提高很多效率
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <cctype> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define debug printf("!\n") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf("\n") #define LL long long int ans[100010]; int main() { int i; mem(ans,0); for(i=1;i<100000;i++) { int m = i,n=i; while(n) { m+=n%10; n/=10; } if(ans[m]==0 || i<ans[m]) ans[m] = i; } int t; sf("%d",&t); pf("%d\n",ans[t]); }