HDU4722Good Numbers热身赛2 1007题(思维题 不用数位dp照样可以做的)
发布时间: 2013-09-12 22:07:04 作者: rapoo
HDU4722Good Numbers热身赛2 1007题(思维题 不用数位dp照样可以做的)
21 101 20
Case #1: 0Case #2: 1HintThe answer maybe very large, we recommend you to use long long instead of int.
#include<iostream>#include<cstring>#include<string>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;char a[12][12];int is(__int64 x){ int ans=0; while(x) { ans+=x%10; x/=10; } if(ans%10==0) return 1; return 0;}int main(){ int tes; __int64 res; __int64 a,b; scanf("%d",&tes); int cas=0; while(tes--) { scanf("%I64d%I64d",&a,&b); while(!is(a)) //先找到>=a的最小数位相加整除10的数 a++; while(!is(b)) //先找到<=b的最大数位相加整除10的数 b--; if(a>b) res=0; else //即为a<=b的时候再用相减的方法,保险起见 res=b/10-a/10+1; //每10个里面有一个 printf("Case #%d: %I64d\n",++cas,res); } return 0;}/*2101 101 2032 4332 4691 1090 1001 100*///46MS 232K