HDU - 3555 Bomb
来源:互联网 发布:java反序列化实例 编辑:程序博客网 时间:2024/06/05 14:40
1.题面
http://acm.hdu.edu.cn/showproblem.php?pid=3555
2.题意
求在[a,b]区间中,有多少数字是含有49这个串的。
3.思路
数位dp,注意到没有限制的时候,后面所能表示的数是一样的
我一开始使用了一种奇怪的写法,不过也过了
4.代码
通过的代码
/***************************************************************** > File Name: Cpp_Acm.cpp > Author: Uncle_Sugar > Mail: uncle_sugar@qq.com > Created Time: 2016年07月27日 星期三 19时33分33秒*****************************************************************/# include <cstdio># include <cstring># include <cctype># include <cmath># include <cstdlib># include <climits># include <iostream># include <iomanip># include <set># include <map># include <vector># include <stack># include <queue># include <algorithm>using namespace std;template<class T>void PrintArray(T* first,T* last,char delim=' '){ for (;first!=last;first++) cout << *first << (first+1==last?'\n':delim); }const int debug = 1;const int size = 10 + 30; const int INF = INT_MAX>>1;typedef long long ll;int num[size];int len;ll dp[30][20][2];ll dfs(int pos,int pre,int statue,int limit){ if (pos==-1) return statue; if (limit!=1&&dp[pos][pre][statue]!=-1) return dp[pos][pre][statue]; int ub = limit?num[pos]:9; ll ret = 0; for (int i=0;i<=ub;i++){ ret += dfs(pos-1,i,statue||(pre==4&&i==9),limit&&i==ub); } if (limit==0) dp[pos][pre][statue] = ret; return ret;}ll solve(ll n){ len = 0; while (n){ num[len++] = n%10; n /= 10; } return dfs(len-1,-1,0,1);}int main(){ std::ios::sync_with_stdio(false);cin.tie(0); int i,j; int T; cin >> T; memset(dp,-1,sizeof(dp)); while (T--){ ll a; cin >> a; cout << solve(a) << endl; } return 0;}
奇怪的写法
/***************************************************************** > File Name: Cpp_Acm.cpp > Author: Uncle_Sugar > Mail: uncle_sugar@qq.com > Created Time: 2016年07月27日 星期三 19时33分33秒*****************************************************************/# include <cstdio># include <cstring># include <cctype># include <cmath># include <cstdlib># include <climits># include <iostream># include <iomanip># include <set># include <map># include <vector># include <stack># include <queue># include <algorithm>using namespace std;template<class T>void PrintArray(T* first,T* last,char delim=' '){ for (;first!=last;first++) cout << *first << (first+1==last?'\n':delim); }const int debug = 1;const int size = 10 + 30; const int INF = INT_MAX>>1;typedef long long ll;int num[size];int len;ll dp[30][20][2][2];ll dfs(int pos,int pre,int statue,int limit){ if (pos==-1) return statue; if (dp[pos][pre][statue][limit]!=-1) return dp[pos][pre][statue][limit]; int ub = limit?num[pos]:9; ll ret = 0; for (int i=0;i<=ub;i++){ ret += dfs(pos-1,i,statue||(pre==4&&i==9),limit&&i==ub); } if (dp[pos][pre][statue][limit]==-1) dp[pos][pre][statue][limit] = ret; return ret;}ll solve(ll n){ memset(dp,-1,sizeof(dp)); len = 0; while (n){ num[len++] = n%10; n /= 10; } return dfs(len-1,0,0,1);}int main(){ std::ios::sync_with_stdio(false);cin.tie(0); int i,j; int T; cin >> T; while (T--){ ll a; cin >> a; cout << solve(a) << endl; } return 0;}
0 0
- hdu HDU 3555 Bomb
- hdu 3555 Bomb
- hdu 3555 Bomb
- HDU 3555 Bomb
- hdu 3555 Bomb
- HDU:3555 Bomb
- HDU 3555 Bomb
- hdu 3555 Bomb
- hdu 3555 Bomb
- hdu 3555 Bomb
- hdu 3555 Bomb
- HDU-3555 Bomb
- hdu-3555-Bomb
- HDU 3555 Bomb
- HDU 3555 Bomb [数位]
- HDU 3555 Bomb
- HDU 3555 Bomb
- HDU 3555 Bomb
- C语言中的关键字
- php中创建文件函数tempnam()与tmpfile()区别
- sdut oj2056 不敢死队问题
- Mac电脑 - “USB 10/100 LAN”的电缆可能未插好,或另一端的设备没有响应。
- [Cloud Computing]Mechanisms: Virtual CPU
- HDU - 3555 Bomb
- 从一个scene跳转到另一个scene的代码以及一些控件代码
- Android Toolbar菜单动态切换item的图标
- input框自动填充内容背景颜色为黄色解决方法
- 2016 Personal Training #6 Div.2
- SDUT3324顺序表应用1:多余元素删除之移位算法
- HDU 5761 Rower Bo(多校3)
- crontab 定时任务
- CentOS6.5安装与配置JDK-7