poj 3286 How many 0's? --- 数位dp
2014-01-27 22:34
337 查看
找找规律就可以
#include <iostream> #include <cstring> #include <string> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #define inf 0x3f3f3f3f #define ll __int64 using namespace std; ll a[12]={1LL,10LL,100LL,1000LL,10000LL,100000LL,1000000LL,10000000LL,100000000LL,1000000000LL,10000000000LL,100000000000LL}; ll cal(ll n) { ll ans=0,left,tmp; for(int i=1;i<12;i++) { left=n/a[i]-1; ans+=left*a[i-1]; tmp=(n%a[i]-n%a[i-1])/a[i-1]; if(tmp>0) ans+=a[i-1]; else if(tmp==0) ans+=n%a[i-1]+1; if(n<a[i]) break; } return ans; } int main() { ll n,m; while(scanf("%I64d%I64d",&n,&m)&&m>=0) { printf("%I64d\n",cal(m)-cal(n-1)); } return 0; }
相关文章推荐
- 线程的状态
- C语言模拟MATRIX特效
- OCP-1Z0-053-V13.02-612题
- 深入理解计算系统读书笔记(一)
- Spring MVC 3.1多视图协商配置(json、xml、freemarker)
- log4j 和slf4j的比较
- POJ 3261 Milk Patterns(后缀数组)
- 黑马程序员__java基础9 包 线程1
- ORA-01795的原因及解决办法
- kettle 源码分析
- sccm安装客户端代理软件
- Linux学习笔记 - Gateway / Router
- STL泛型编程学习之String系列容器
- 关于续行符
- CMUSphinx Wiki--Open Source Toolkit For Speech Recognition
- 新版微信全体验――微信5.2 for iPhone (高富帅尊享版)
- Linux学习笔记 - 主機的 IP 是如何設定的
- eclipse快捷键大全
- 《数学之美》信息整合以及个人领悟
- 《软件测试》学习笔记