LightOj 1163 - Bank Robbery(x-x/10 = n求所有的 x )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1163
题意:有一个数A,然后去掉A的最后一位得到B,先告诉你A-B的值,求所有满足条件的A,按从小到大的顺序输出;
其实就是x-x/10=n求所有的 x(这里的x/10是取整)
还可以写成是:num*10+r - num = n,其中num*10+r = A, n = B, r是A的个位数字;r一定是0-9中的一个数,可以枚举,所以可以得到 9 * num = n-r;
所以只要找到所有的r是的(n-r)%9 == 0即可;
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> typedef unsigned long long LL; #define N 1000001 using namespace std; const double eps = 1e-6; int main() { int T, t = 1; scanf("%d", &T); while(T --) { LL n; scanf("%llu", &n); LL ans[11] = {0}; int k = 0; for(int i=0; i<=9; i++) { if((n-i)%9 == 0) ans[k++] = (n-i)/9*10+i; } sort(ans, ans+k); k = unique(ans, ans+k) - ans; printf("Case %d:", t++); for(int i=0; i<k; i++) printf(" %llu", ans[i]); printf("\n"); } return 0; }