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. 网页中获取网络mp3文件的时常

    <html> <audio id="audio" controls> <source src="http://cdn.kaishuhezi. ...

  2. 面试题:在O(1)时间删除链表结点

    题目:给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点. 链表结点与函数的定义如下: struct ListNode { int m_nValue; ListNode* m_p ...

  3. CentOS 6.4下Squid代理服务器的安装与配置,反向代理

    CentOS 6.4下Squid代理服务器的安装与配置 一.简介 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息. Squid是一个缓存Internet 数据的软件 ...

  4. SharePoint BCS

    1. 开启相关的服务:管理中心-->应用程序管理-->管理服务器上的服务 2.

  5. U3D navmesh寻路简单示范

    要求:放置一个BOSS,创建几个路标,自动循环这几个路标形成回路,变成自动巡逻,并配合animator系统的控制开关控制BOSS的动作 1.先设置好BOSS 中animator的控制开关,只看Run和 ...

  6. .net EF中从数据添加表或视图时无法添加的问题

    .net 使用EF模式进行开发,添加实体时不能够正常添加 错误描述: .net中在EF文件中添加数据库中已有的表或视图时不能正常添加,在添加时没有任何的错误提示,但是表或视图就一直拉不过来,,保存也没 ...

  7. [Swust OJ 412]--医院设置(floyd算法)

    题目链接:http://acm.swust.edu.cn/problem/412/ Time limit(ms): 1000 Memory limit(kb): 65535   Description ...

  8. C# Programming Study #1

    引用的时候需要在参数和使用的时候加上 ref 关键字 static bool addnum (ref int val) //引用 { ++val; return true; } 参数数组的概念,可以接 ...

  9. FPGA知识大梳理(三)verilogHDL语法入门(2)知识汇总

    1,时序逻辑.将上次的练习修改成时序逻辑会如何设计. always @ (posedge clock) 2,block 与unblocking  A,有clock的always中通常使用nonbloc ...

  10. open和fopen的区别:

    1.缓冲文件系统缓冲文件系统的特点是:在内存开辟一个“缓冲区”,为程序中的每一个文件使用,当执行读文件的操作时,从磁盘文件将数据先读入内存“缓冲区”, 装满后再从内存“缓冲区”依此读入接收的变量.执行 ...