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的更多相关文章

  1. 组合数学第一发 hdu 2451 Simple Addition Expression

    hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...

  2. 10994 - Simple Addition(规律)

    Problem E Simple Addition Input: Standard Input Output: Standard Output Let’s define a simple recurs ...

  3. HDU 2451 Simple Addition Expression(组合数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 pass ...

  4. HDU2451:Simple Addition Expression

    Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twiligh ...

  5. uva 10994 - Simple Addition(规律)

    题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...

  6. 【计数】Simple Addition Expression

    [来源] 2008年哈尔滨区域赛 [题目链接]: http://acm.hdu.edu.cn/showproblem.php?pid=2451 [参考博客]: HDU 2451 Simple Addi ...

  7. 【HDOJ】2451 Simple Addition Expression

    递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41- ...

  8. uva 10994 - Simple Addition

    //组合数学 //计算sum{i从右往左数的第一个非0数字,p<=i<=q}. #include <cstdio> typedef long long ll; ll sum(l ...

  9. HDU 2451 Simple Addition Expression

    题目大意:有一个关于 简单加法表达式  的定义告诉你,就是  选一个数字i  如果 i+(i+1)+(i+2) 它的和,没有任何一位进位的话,那就是 一个i的简单加法表达式,求小于n的表达式数目. 题 ...

随机推荐

  1. python异常处理try,except,else,finally,raise

    先看下else的使用: try: ... exception: ... else: ... 只有在try中没有发生任何异常,所有代码完全成功的情况下才会转入else 再看下finally: final ...

  2. HDU 2815 Mod Tree

    不会,先搁着…… http://blog.csdn.net/acm_cxlove/article/details/7832197

  3. Ghost.py 0.1b3 : Python Package Index

    Ghost.py 0.1b3 : Python Package Index Ghost.py 0.1b3 Download Ghost.py-0.1b3.tar.gz Webkit based web ...

  4. Airport(未解决。。。)

    Airport Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  5. echarts 应用数个样例

    应用一:环形图和饼图嵌套 先说明一下内部文件分布: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGV4dGJveQ==/font/5a6L5L2T/fo ...

  6. 对象图(Object Diagram)—UML图(三)

    一.用一张图来介绍一下对象图的基本内容 二.对象图与类图的基本差别 三.对象图实例

  7. windows上运行npm Error: ENOENT, stat 'C:\Users\

    node 中 npm报错 Error: ENOENT, stat C:\Users\Administrator\AppData\Roaming\npm 报错原因可能是修改了node的默认安装路径.于是 ...

  8. 在Tableau中自定义版块地图 (Polygon)

    在Tableau的地图报表中有一个‘Filed Map’的类型,可以根据版块来显示数据. 但实际应用中Tableau固有的版块划分可能不是我们想要的,下面介绍如何自定义版块并且用作数据分析. 自定义版 ...

  9. KMP算法的一个C++实现

    本文参考阮一峰老师的KMP算法,重点是“部分匹配表”的建立.算法可参考 http://kb.cnblogs.com/page/176818/ . /* * kmp.cpp * Author: Qian ...

  10. Dojo实现Tabs页报错(三)

    用Dojo实现tab页的过程中,没有引用“on.js”,但是firebug调试时一直提示如下错误: on.js源码如下: define(["./has!dom-addeventlistene ...