Simple Addition
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=31329#problem/V
使用题目所给函数,单单从某一个数字来看,就是直接求这个数各个数位上的和;而且p=====>q之间的数调用这个函数,其数值都是在1~9之间;因此,求x和y%10的值,然后就直接45*((y-x)/10 );45是1+2+。。。+9的和,后面代表,p和q之间拥有多少个满足条件的组数,然后直接使用DFS递推即可
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<stack>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<sstream>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional> using namespace std ;
long long ans , p , q ;
long long f( long long n )
{
if( n == 0 )
return 0 ;
else if( n % 10 )
{
return n % 10 ;
}
else
{
return f( n / 10 ) ;
}
} void DFS( long long x , long long y )
{
long long i , j ;
if( y - x < 10 )
{
for( int i = x ; i <= y ; ++i )
{
ans += f( i ) ;
}
return ;
}
for( i = x ; i % 10 != 0 ; ++i )
{
ans += f( i ) ;
}
for( j = y ; j % 10 != 0 ; --j )
{
ans += f( j ) ;
}
ans += 45 * ( ( j - i ) / 10 );
DFS( i / 10 , j / 10 ) ;
}
int main()
{ while( scanf( "%lld%lld" , &p , &q ) != EOF )
{
if( p == -1 && q == -1 )
break ;
ans = 0 ;
DFS( p , q ) ;
printf( "%lld\n" , ans ) ;
}
return 0 ;
}
Simple Addition的更多相关文章
- 组合数学第一发 hdu 2451 Simple Addition Expression
hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...
- 10994 - Simple Addition(规律)
Problem E Simple Addition Input: Standard Input Output: Standard Output Let’s define a simple recurs ...
- HDU 2451 Simple Addition Expression(组合数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 pass ...
- HDU2451:Simple Addition Expression
Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twiligh ...
- uva 10994 - Simple Addition(规律)
题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...
- 【计数】Simple Addition Expression
[来源] 2008年哈尔滨区域赛 [题目链接]: http://acm.hdu.edu.cn/showproblem.php?pid=2451 [参考博客]: HDU 2451 Simple Addi ...
- 【HDOJ】2451 Simple Addition Expression
递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41- ...
- uva 10994 - Simple Addition
//组合数学 //计算sum{i从右往左数的第一个非0数字,p<=i<=q}. #include <cstdio> typedef long long ll; ll sum(l ...
- HDU 2451 Simple Addition Expression
题目大意:有一个关于 简单加法表达式 的定义告诉你,就是 选一个数字i 如果 i+(i+1)+(i+2) 它的和,没有任何一位进位的话,那就是 一个i的简单加法表达式,求小于n的表达式数目. 题 ...
随机推荐
- FIB数列
斐波那契级数除以N会出现循环,此周期称为皮萨诺周期. 下面给出证明 必然会出现循环 这是基于下面事实: 1. R(n+2)=F(n+2) mod P=(F(n+1)+F(n)) mod P=(F(n+ ...
- N bulbs(规律)
N bulbs Accepts: 408 Submissions: 1224 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 655 ...
- Tree(未解决。。。)
Tree Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- leetcode_question_70 Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- 开发板-PC机(宿主机)-虚拟机(VM)之间网络通信设置方法及须要注意的问题
1.不使用路由器交换机 硬件连接: 使用网线将开发板和PC机相连 串口线将PC机和开发板相连 使用命令: ifconfig -a 串口控制端查看开发板的网络配置 route -n 串口控制端查看开发板 ...
- Eclipse新建Android工程,在模拟器运行的时候提示Unfortunately,XXX has stopped.
刚新建好的android工程在模拟器运行的时候出错,提示Unfortunately,XXX has stopped 查看Eclipse下面的错误信息,双击第一条 把ActionBarActivity前 ...
- java数据结构与算法值优先级队列
一.优先级队列 什么是优先级队列:优先级队列是一种比栈和队列更加常用的一种数据结构.在优先级队列中,数据项按照关键字的值有序.数据项插入到队列中时,会按照顺序插入到合适的位置,用来保证队列的顺序. 生 ...
- BZOJ 1806: [Ioi2007]Miners 矿工配餐( dp )
dp... ------------------------------------------------------------------------------- #include<cs ...
- python命令行解析工具argparse模块【5】
上一节我们学习了parse_args()的用法,这一节,我们将继续学习argparse的其他一些用法. 1.sub-commands子命令 argpar ...
- Startup 和 Middleware(中间件)
Startup 和 Middleware(中间件) ASP.NET Core 运行原理剖析2:Startup 和 Middleware(中间件) Startup Class 1.Startup Con ...