A - 不要62
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
Input
输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。
Output
对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。
Sample Input
1 100
0 0
Sample Output
80
要不出现4和62,数位dp,两种方法,一种是先用数组存每个位数上的数字的时候有多少答案,另一种是数位dp的模板写法,临时求,不过可以用dp数组存已经找过的
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define sca(x) scanf("%d",&x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1000005;
int dp[15][15];
int num[15];
void first()
{
mm(dp,0);dp[0][0]=1;
rep(i,1,10)
rep(j,0,10)
{
if(j==4)
continue;
else
rep(k,0,10)
{
if(j==6&&k==2)
continue ;
dp[i][j]+=dp[i-1][k];
}
}
}
int solve(int x)
{
int n=x,cnt=1,ans=0;
while(n>0)
{
num[cnt++]=n%10;
n/=10;
}
num[cnt]=0;
per(i,cnt-1,1)
{
rep(j,0,num[i])
{
if(j==4||(j==2&&num[i+1]==6))
continue;
ans+=dp[i][j];
}
if(num[i]==4||(num[i]==2&&num[i+1]==6))
break;
}
return ans;
}
int main()
{
first();
int l,r;
while(cin >> l >>r &&(l||r))
{
cout<<solve(r+1)-solve(l)<<endl;
}
return 0;
}
数位dp模板写法
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define sca(x) scanf("%d",&x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1000005;
int dp[15][2];
int num[15];
int dfs(int pos,int if6,int limit)
{
int ans=0;
if(!pos) return 1;
int up=limit?num[pos]:9;
if(!limit&&dp[pos][if6]!=-1) return dp[pos][if6];
rep(i,0,up+1)
{
if(i==4) continue;
if(i==2&&if6) continue;
ans+=dfs(pos-1,i==6,limit&&i==up);
}
if(!limit) dp[pos][if6]=ans;
return ans;
}
int solve(int x)
{
mm(num,0);
int pos=0;
while(x)
{
num[++pos]=x%10;
x/=10;
}
return dfs(pos,0,1);
}
int main()
{
mm(dp,-1);
int l,r;
while(cin >> l >>r &&(l||r))
{
cout<<solve(r)-solve(l-1)<<endl;
}
return 0;
}
A - 不要62的更多相关文章
- VS2015编译boost1.62
VS2015编译boost1.62 Boost库是一个可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一. Boost库由C++标准委员会库工作组成员发起,其中有些内容有 ...
- P87LPC760/61/62/64/67/68/69/78/79芯片解密单片机破解价格
NXP恩智浦P87LPC760/61/62/64/67/68/69/78/79芯片解密单片机破解 NXP LPC700系列单片机解密型号: P87LPC759.P87LPC760.P87LPC761. ...
- HDU2089 不要62[数位DP]
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Connection broken for id 62, my id = 70, error =
启动费zokeeper失败,报错如下:Connection broken for id 62, my id = 70, error = 原因是因为zoo.cfg中server.id不正确. serve ...
- base64/62 加解密的实现。
base64/62加解密代码下载地址: http://files.cnblogs.com/files/Kingfans/base64(62)加解密.zip base64: base62:
- /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’
/usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’/usr/include/linux/types.h:13: erro ...
- [HDU2089]不要62
[HDU2089]不要62 试题描述 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就 ...
- NYOJ题目62笨小熊
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr4AAAK1CAIAAAChInrhAAAgAElEQVR4nO3dO3LjutaG4X8Szj0Qxx
- 62个Android Studio小技巧合集
1书签(Bookmarks) 描述:这是一个很有用的功能,让你可以在某处做个标记(书签),方便后面再跳转到此处. 调用:Menu → Navigate → Bookmarks 快捷键: 添加/移除书签 ...
- [ACM_水题] 不要62(hdu oj 2089, 不含62和4的数字统计)
Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来, ...
随机推荐
- Your project is not referencing the ".NETPortable,Version=v4.5,Profile=Profile259" framework. Add a reference to ".NETPortable,Version=v4.5,Profile=Profile259" in the "frameworks" section of your proj
i want to add nuget packages to my portable class library project , then i add a project.json to my ...
- Accounting Calendar template
SELECT INITCAP (TO_CHAR (TO_DATE (&year || '-' || LPAD (ROWNUM, 2, '0'), 'yyyy-mm'), 'MON', 'NLS ...
- 两个UITableView的级联菜单
效果 源码 https://github.com/YouXianMing/Animations 说明 1. TwoLevelLinkageView封装了两个tableView,左边tableView中 ...
- scipy.stats
scipy.stats Scipy的stats模块包含了多种概率分布的随机变量,随机变量分为连续的和离散的两种.所有的连续随机变量都是rv_continuous的派生类的对象,而所有的离散随机变量都是 ...
- SharePoint Excel Service - Couldn't Open the Workbook.
Error meesage: "Couldn't Open the Workbook. Wow, That's a big workbook. Unfortunately, we can't ...
- JS对HTML字符的转义
function htmlEscape(str){ var s = ""; if(str.length == 0) return ""; s = str.rep ...
- Android 获取Activity当前view
View cv = getWindow().getDecorView(); 来自为知笔记(Wiz)
- centos7.0安装cuda驱动
00.CUDA简介 CUDA和GPU的并行处理能力来加速深度学习和其他计算密集型应用程序 01.CPU+GPU协同架构 02.部署环境 [docker@lab-250 ~]$ cat /etc/*re ...
- js实现sleep
1.这种不是匀速, 写到for循环中出现1,2,3.......456....的情况 function sleep(milliseconds) { var start = new Date().get ...
- Effective Java 第三版笔记(目录)
<Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将近8年的时 ...