HDU 4722 Good Numbers

来源:互联网 发布:ubuntu解压缩命令 编辑:程序博客网 时间:2024/04/30 21:32
If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number. 
You are required to count the number of good numbers in the range from A to B, inclusive.
Input
The first line has a number T (T <= 10000) , indicating the number of test cases. 
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
Output
For test case X, output "Case #X: " first, then output the number of good numbers in a single line.
Sample Input
21 101 20
Sample Output
Case #1: 0Case #2: 1          
Hint
The answer maybe very large, we recommend you to use long long instead of int.         可以数位dp,不过其实直接找规律就可以了,打个表可以看出来,我取了100作为结果,当然取10更好。
#include<map>   #include<set>  #include<ctime>    #include<cmath>   #include<stack>#include<queue>     #include<string>    #include<vector>    #include<cstdio>        #include<cstring>      #include<iostream>    #include<algorithm>        #include<functional>    using namespace std;#define ms(x,y) memset(x,y,sizeof(x))        #define rep(i,j,k) for(int i=j;i<=k;i++)        #define per(i,j,k) for(int i=j;i>=k;i--)        #define loop(i,j,k) for (int i=j;i!=-1;i=k[i])        #define inone(x) scanf("%d",&x)        #define intwo(x,y) scanf("%d%d",&x,&y)        #define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)      #define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p)     #define lson x<<1,l,mid    #define rson x<<1|1,mid+1,r    #define mp(i,j) make_pair(i,j)    #define ff first    #define ss second    typedef long long LL;typedef pair<int, int> pii;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 1e5 + 10;const double eps = 1e-10;int T, cas = 1;LL n, m;LL calc(LL x){if (x < 0) return 0;LL y = x / 100 * 100, z = 0;for (; y <= x; y++){int sum = 0;for (LL i = y; i; i /= 10) sum += i % 10;if (sum % 10) continue;z++;}return x / 100 * 10 + z;}int main(){for (inone(T); T--; cas++){scanf("%lld%lld", &n, &m);printf("Case #%d: %lld\n", cas, calc(m) - calc(n - 1));}return 0;}

0 0
原创粉丝点击