找规律/数位DP HDOJ 4722 Good Numbers

 

题目传送门

 1 /*  2  找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one ()  3 http://www.cnblogs.com/crazyapple/p/3315436.html  4  数位DP:http://blog.csdn.net/cyendra/article/details/11606209  5 */  6 #include <cstdio>  7 #include <iostream>  8 #include <algorithm>  9 #include <cstring> 10 #include <string> 11 #include <cmath> 12 using namespace std; 13 14 const int MAXN = 1e5 + 10; 15 const int INF = 0x3f3f3f3f; 16 17 int is_one(long long n) 18 { 19 long long m = n; 20 long long i = n / 10 * 10; 21 22 for (; i<=m; ++i) 23  { 24 long long tmp = i; int sum = 0; 25 while (tmp) 26  { 27 sum += tmp % 10; 28 tmp /= 10; 29  } 30 if (sum % 10 == 0) return 1; 31  } 32 33 return 0; 34 } 35 36 long long get_num(long long n) 37 { 38 if (n < 0) return 0; 39 if (n <= 10) return 1; 40 41 return n/10 + is_one (n); 42 } 43 44 int main(void) //HDOJ 4722 Good Numbers 45 { 46 //freopen ("G.in", "r", stdin); 47 48 int t, cas = 0; 49 long long l, r; 50 scanf ("%d", &t); 51 while (t--) 52  { 53 scanf ("%I64d%I64d", &l, &r); 54 55 printf ("Case #%d: %I64d\n", ++cas, get_num (r) - get_num (l-1)); 56  } 57 58 return 0; 59 } 60 61 62 /* 63 Case #1: 0 64 Case #2: 1 65 Case #3: 1 66 */

 

你可能感兴趣的:(number)