题目链接: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. linux运维工程师,必须掌握以下几个工具

    本人是linux运维工程师,对这方面有点心得,现在我说说要掌握哪方面的工具吧说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具.我就大概列出这几方面,这样入门就基本没问题了 ...

  2. 数据库创建&数据表创建

    --第2_1题创建数据库 create database Student201038897041 on primary (name='student1', filename='F:\coures\SQ ...

  3. Kivy中文显示

    Win7系统 下载 DroidSansFallback.ttf字体(android设备上自带了) 源代码第一行增加#-*- coding:utf-8 -*- 创建widget值定font_name s ...

  4. PCB设计之原理图绘制笔记

    02原理图工作环境设置原理图画布由画布和边界(Border)构成.可以通过DocumentOptions设置(快捷键DO).DocumentOptions设置--------------------- ...

  5. SQL Server 2012 Features

    SQL SQL Server 2012 新增加的几个函数: SELECT CONVERT (INT, 'Angkor-216.00') 直接报错 SELECT TRY_CONVERT(INT, 'SS ...

  6. Latex 常用知识点存档

    前言: 本篇仅作为自己的知识存档. $Latex$是什么,就不用介绍了,网上好多教程和知识点,当忘记的时候搜一下就可以了. 本科做美赛和毕设的时候用的$Latex$排版,最近开始在博客园写点东东,发现 ...

  7. 自定义scrollbar

    Chrome ::-webkit-scrollbar 整体部分 ::-webkit-scrollbar-track 轨道 ::-webkit-scrollbar-track-piece 内层轨道 :: ...

  8. sqrt和Hailstone

    求平方根 class SqRoot{ void calcRoot(double z){ double x=1;double y=z/x; while(Math.abs(x-y)>1E-10) { ...

  9. delphi xe5 android 开发数据访问手机端(二)

    界面就这样吧,继续...,先启动咱们上几片文章建立的手机服务端 导入webservices单元,file->new->other->webservices->选择 wsdlim ...

  10. python下redis的基本操作:

    1. 基本操作: >>> import redis >>> print redis.__file__ /usr/local/lib/python2.7/dist-p ...