欢迎访问https://blog.csdn.net/lxt_Lucia~~
宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~
不要62 ( HDU 2089 )
Description
杭州人称那些傻乎乎粘嗒嗒的人为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
Author
qianneng
Source
Recommend
lcy | We have carefully selected several similar problems for you: 2094 2090 2091 2093 2092
题意:
多组输入m,n,( m,n,同为0停止输入 ) ,定义不含数字4且不含“62”的数为吉利数,“62”表示6在前2在后,并且6和2连在一起,注意“26”不影响,求在 ( m , n )区间内有多少吉利数。
代码(模板):
#include<map>
#include<stack>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define eps 1e-10
#define LL long long int
using namespace std;
LL dp[10][20],a[20];
void init()
{
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<=7;i++)
{
for(int j=0;j<=9;j++)
{
if(j==4)
{
dp[i][j]=0;
}
else
{
for(int k=0;k<=9;k++)
{
if(!(j==6&&k==2))
dp[i][j]+=dp[i-1][k];
}
}
}
}
}
LL solve(int x) //查找(0,x)区间内有多少个符合条件的
{
LL ans=0,len=0;
while(x)
{
a[++len]=x%10;
x/=10;
}
a[len+1]=0;
for(int i=len;i>=1;i--)
{
for(int j=0;j<=a[i]-1;j++)
{
if((j==4)||(a[i+1]==6&&j==2))
continue;
else ans+=dp[i][j];
}
if((a[i]==4)||(a[i+1]==6&&a[i]==2))
break;
}
return ans; //返回(0,x)区间内有符合条件的个数
}
int main()
{
int n,m;
init();
while(scanf("%d%d",&m,&n)&&(m||n))
printf("%lld\n",solve(n+1)-solve(m)); 计算(m,n)区间内符合条件的个数
return 0;
}