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. 输出1到最大的N位数

    题目:输入数字n,按顺序输出从1最大的n位10进制数.比如输入3,则输出1.2.3一直到最大的3位数即999. 分析:这是一道很有意思的题目.看起来很简单,其实里面却有不少的玄机. 应聘者在解决这个问 ...

  2. zookeeper leader作用

    一个zookeeper 集群 只有一个leader: 类似master/slave模式 客户端提交请求之后,先发送到leader,leader作为接收者,广播到每个server 在folloer上创建 ...

  3. zookeeper 同步

    <pre name="code" class="html">一个节点上的数据发生变化后,通知其他节点 server 1: [root@wx03 bi ...

  4. A计划(bfs)

    A计划 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  5. Android 中文API (65) —— BluetoothClass[蓝牙]

    前言 本章内容是android.bluetooth.BluetoothClass,为Android蓝牙部分的章节翻译.用于描述远端设备的类型,特点等信息,通过getBluetoothClass()方法 ...

  6. windows上的tomcat配置

    下载及安装 首先要安装JDK:jdk-7windows-x64.zip 再安装tomcat:apache-tomcat-7.0.23-windows-x64.zip   配置环境变量: CATALIN ...

  7. Xcode 插件优缺点对比(推荐 20 款插件)

    链接地址:http://mp.weixin.qq.com/s?__biz=MjM5OTM0MzIwMQ==&mid=402439598&idx=1&sn=e8800cb0aa2 ...

  8. Aptana Studio 3 官方汉化包汉化

    Babel Language Pack Update Site for Helios This URL is an Eclipse software repository:http://downloa ...

  9. 【转载】Google Analytics 使用图文全攻略

    转载自:Google Analytics 使用图文全攻略 最近一段时间,因为工作的需要,小励使用GA(GA是Google Analytics的简称)比较频繁,所以花时间研究了一下,从不太了解到会使用( ...

  10. python:利用asyncio进行快速抓取

    web数据抓取是一个经常在python的讨论中出现的主题.有很多方法可以用来进行web数据抓取,然而其中好像并没有一个最好的办法.有一些如scrapy这样十分成熟的框架,更多的则是像mechanize ...