题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722

Good Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 422    Accepted Submission(s): 146

Problem Description
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
2
1 10
1 20
 
Sample Output
Case #1: 0
Case #2: 1
 
题目大意:找出给定范围内数位和能被10整除的数的数目
 
解题思路:不难发现,以100个数为一组,每组有10个数满足条件,对于给定的数,先找有多少组,对剩余的数暴搜一遍就能得到结果。
 
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int keng(long long x,int left)
{
int n=,i,ans;
while(x)
{
n+=x%;
n%=;
x/=;
}
ans=left/;
i=-(n+ans)%;
if(i==)
i=;
if(left%>=i)
ans++;
return ans;
}
bool check(long long a)
{
int n=;
while(a)
{
n+=a%;
n%=;
a/=;
}
if(n%==)
return true;
else return false;
}
int main()
{
int t,i,Case,shu;
long long a,b;
long long Ca,Cb;
long long left;
scanf("%d",&t);
// a=1;
for(Case=;Case<=t;Case++)
{
// b=Case;
scanf("%I64d%I64d",&a,&b);
Ca=a/*;left=a%;
Ca=keng(Ca/,left)+Ca;
if (check(a)) Ca--;
Cb=b/*;left=b%;
Cb=keng(Cb/,left)+Cb;
printf("Case #%d: %I64d\n",Case,Cb-Ca);
}
return ;
}

HDU 4722 Good Numbers的更多相关文章

  1. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

  2. hdu 4722 Good Numbers(规律题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4722 [题意]: 找GoodNumbers一个数N,如果它每一个位数字之和可以整除10,那么它就是GoodNum ...

  3. HDU 4722 Good Numbers 2013年四川省赛题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 题目大意:给定一个区间,求区间中有多少个满足每位上的数的和是10的倍数. 解题思路:先打表暴力求 ...

  4. HDU 4722 Good Numbers(位数DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description If we sum up every digit of a number and the result can be exactly divided by 10, we say ...

  5. hdu 4722 Good Numbers 规律 数位dp

    #include<iostream> #include<cstring> #include<cstdio> #include<vector> #incl ...

  6. hdu 4722 Good Numbers( 数位dp入门)

    Good Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. HDU - 4722 Good Numbers 【找规律 or 数位dp模板】

    If we sum up every digit of a number and the result can be exactly divided by 10, we say this number ...

  8. HDU 4722 Good Numbers(DP)

    题目链接 脑子有点乱,有的地方写错了,尚大婶鄙视了... 来个模版的. #include <iostream> #include <cstdio> #include <c ...

  9. hdu 4722 Good Numbers 数位DP

    数位DP!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include< ...

随机推荐

  1. PHP & Javascript 如何对字符串中包含html标签进行编码 整理

    为什么要对字符串编码? 某些字符串中包含html标签,不编码,页面输出就乱了. PHP下怎么对字符串编码? htmlentities vs htmlspecialchars htmlentities ...

  2. ASP.net+MVC--2

    1.ASP.NET MVC控制器 1)在Controllers文件夹下新建控制类 public class HelloWorld2Controller : Controller { public st ...

  3. 阿里云服务器CentOS 5.7(64位)安装配置LAMP服务器(Apache+PHP5+MySQL)

    一.快速安装Apache+PHP5+MySql ----------------------------------------------------- 补充:由于163的yum源上只有php5.1 ...

  4. session阻塞机制,解决方法

    session从生成到读取,或从生成到写入都出现锁定的情况. 1.session_start();session_commit(); 2.session_start();session_write_c ...

  5. 【javascript 变量和作用域】

    今天学习了javascript 的变量和作用域的基本知识,对于以前在开发中遇到的一些不懂的小问题也有了系统的认识,收获还是比较多的. [基本类型和引用类型] ECMAScript 变量可能包含两种不同 ...

  6. .Net平台下的B/S开发框架

    一.前言 本文主要是对.Net平台下的几种B/S开发框架进行比较.只对比前端展现和界面业务逻辑的部分,对于后台的数据层.业务层.持久层等则不作讨论,因为这些部分是完全可以共用的.  主要从如下几个维度 ...

  7. 加密算法 - RSA算法一

    RSA算法原理(一)  声明: 本文转自 -- 作者: 阮一峰 (http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html) ...

  8. C++的类和对象

    #include <iostream> // 预处理命令 using namespace std; class Student{ // 声明一个类,类名为Student private : ...

  9. [转贴]gsoap使用心得!

    最近换了个工作环境,现在在大望路这边上班,呵,刚上班接到的任务就是熟悉gsoap!废话少说,现在开始gSoap学习! gSOAP是一个夸平台的,用于开发Web Service服务端和客户端的工具,在W ...

  10. Excel列表部分列表隐藏与取消隐藏

    Excel列表部分列表隐藏与取消隐藏 2014-2-19 隐藏:选中需要隐藏的列(选中A.B.C....),右键单击所选部分,选择"隐藏"即可. 取消隐藏:从A选中至所见表格最后的 ...