Eason

Acceteped : 57   Submit : 129
Time Limit : 1000 MS   Memory Limit : 65536 KB

Description

题目描述

Eason是个非常迷信的人,他喜欢数字3和6,不喜欢4和7。 如果一个数字的数码中没有4和7,而有3或者6的话,他就会喜欢这个数字。 比如,他会喜欢13,36,但是不会喜欢14,34。但对于28这种的,他就无所谓喜欢还是不喜欢。 Eason想知道区间[a,b]中一共有多少个他喜欢和不喜欢的数字?

输入

每行输入一个样例,为a和b,0≤a≤b≤106。如果a和b都为0,那么输入结束,这个样例不需要处理。

输出

每行输出一个样例的结果,先输出喜欢数字的个数,再输出不喜欢数字的个数。

样例输入

1 10
1 100
1 1000000
0 0

样例输出

2 2
28 36
215488 737856
 

Sample Input

 
 

Sample Output

 
 

Source

解题:暴力或者数位dp乱搞

先上暴力的解法:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
int ans[],uu[];
void go(int dep,int cur,int step,bool like,bool ulike){
if(step > dep || like && ulike) return;
ans[cur] = like;
if(!like && !ulike) uu[cur] = ;
for(int i = step?:; i <= ; ++i)
go(dep,cur*+i,step+,like||i == ||i == ,ulike||i == ||i == );
}
int main(){
go(,,,false,false);
uu[] = ;
for(int i = ; i < ; ++i){
ans[i] += ans[i-];
uu[i] += uu[i-];
}
int a,b;
while(scanf("%d %d",&a,&b),a||b){
int tmp = ans[b]-ans[a-];
printf("%d %d\n",tmp,(b-a+)-(uu[b]-uu[a-])-tmp);
}
return ;
}

写得比较挫,很多冗余计算。。。后来改了下,起码好看得多了

 #include <cstdio>
int ans[],uu[],arr[] = {,,,,,,,},a,b;
bool check[] = {false,false,false,true,false,true};
void go(int dep,int cur,int step,bool like){
if(step > dep) return;
if(like) ans[cur] = ;
else uu[cur] = ;
for(int i = step?:; i < ; ++i)
go(dep,cur*+arr[i],step+,like||check[i]);
}
int main(){
go(,,,false);
uu[] = ;
for(int i = ; i < ; ++i){
ans[i] += ans[i-];
uu[i] += uu[i-];
}
while(scanf("%d %d",&a,&b),a||b){
int tmp = ans[b]-ans[a-];
printf("%d %d\n",tmp,(b-a+)-(uu[b]-uu[a-])-tmp);
}
return ;
}

然后是数位dp

 #include <cstdio>
#include <cstring>
int dp[][];
void calc(char *str,int &x,int &y){
bool xh = false,bxh = false;
int len = strlen(str);
static const int cnt[] = {,,,,,,,,,};
static const int cnt2[] = {,,,,,,,,,};
for(int i = x = y = ; str[i+]; ++i){
int p = (str[i] > '') + (str[i] > '');
if(!bxh){
if(xh) x += cnt[str[i]-'']*(dp[len-i-][]+dp[len-i-][]);
else{
x += cnt[str[i]-'']*dp[len-i-][] + p*dp[len-i-][];
y += cnt2[str[i]-'']*dp[len-i-][];
}
}
if(str[i] == '' || str[i] == '') bxh = true;
if(str[i] == '' || str[i] == '') xh = true;
}
for(int i = ; i <= str[len-]-''; ++i){
if(!xh && !bxh &&(i == || i == )) ++x;
if(xh && !bxh && i != && i != ) ++x;
if(!bxh && !xh && i != && i != && i != && i != ) ++y;
}
}
int main(){
dp[][] = ;
dp[][] = ;
for(int i = ; i <= ; ++i){
dp[i][] = (dp[i-][]<<) + (dp[i-][]<<);
dp[i][] = *dp[i-][];
}
char str[];
int a,b;
while(scanf("%d %d",&a,&b),a||b) {
int x,y,x1,y1;
sprintf(str,"%d",--a);
calc(str,x,y);
sprintf(str,"%d",b);
calc(str,x1,y1);
int tmp = x1 - x;
printf("%d %d\n",tmp,b-a-tmp-y1+y);
}
return ;
}

1193 Eason的更多相关文章

  1. bzoj 1193 贪心

    如果两点的曼哈顿距离在一定范围内时我们直接暴力搜索就可以得到答案,那么开始贪心的跳,判断两点横纵坐标的差值,差值大的方向条2,小的条1,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...

  2. bzoj 1193

    http://www.lydsy.com/JudgeOnline/problem.php?id=1193 大范围贪心,小范围宽搜. 膜拜大神 http://blog.csdn.net/u0129155 ...

  3. bzoj 1193 贪心+bfs

    1193: [HNOI2006]马步距离 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2015  Solved: 914[Submit][Statu ...

  4. 1193: [HNOI2006]马步距离

    1193: [HNOI2006]马步距离 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2027  Solved: 915[Submit][Statu ...

  5. 九度OJ 1193:矩阵转置 (矩阵计算)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1673 解决:1132 题目描述: 输入一个N*N的矩阵,将其转置后输出.要求:不得使用任何数组(就地逆置). 输入: 输入的第一行包括一个 ...

  6. BZOJ 1193 [HNOI2006]马步距离:大范围贪心 小范围暴搜

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1193 题意: 给定起点(px,py).终点(sx,sy).(x,y < 100000 ...

  7. hpuoj 1193: Interval

    Interval [STL.双指针.二分] 题目链接 http://acm.hpu.edu.cn/problem.php?id=1193 或者 题目链接 http://acm.nyist.net/Ju ...

  8. Vijos 1193 扫雷 【动态规划】

    扫雷 描述 相信大家都玩过扫雷的游戏.那是在一个n*n的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”任过流行起了一种简单的扫雷游戏,这个游戏规则和扫雷一样,如果某个格子没有雷,那么它 ...

  9. JOBDU 1193 矩阵转置

    啊!!!这道题目今天竟然写错了!!!这道题目巨坑,说不能用数组,结果竟然是用数组做的,吐血!!! 看的所有有关博文,都是用数组做的,晕倒!真的出题人有毛病,出这种题,又不限制运行!!! 以后再遇到这种 ...

随机推荐

  1. SGU 180 Inversions【树状数组】

    题意:求逆序数 和POJ那题求逆序数的一样,不过这题离散化之后,要去一下重,然后要开到long long #include<iostream> #include<cstdio> ...

  2. IIS支持10万个同时请求的设置

    1. 调整IIS 7应用程序池队列长度 由原来的默认1000改为65535. IIS Manager > ApplicationPools > Advanced Settings Queu ...

  3. Nginx域名配置文件bak

    server { listen 80; server_name m.abd.com; rewrite ^(.*)$ https://$host$1 permanent; } server { list ...

  4. 多任务-进程之进程池Pool

    1.什么是池? 首先从字面上看,池代表着一个容器,用来承载着某些内容的容器,了解到这里,就对进程池有了一个初步的轮廓. 2.什么是进程池Pool? (1)利用现实中的事物来理解: 对于小白初学者,接触 ...

  5. python 之 MRO 异常

    今天突然遇到这个异常,先贴两个地址,待有时间写博客 https://www.jianshu.com/p/fea6e0a0cc14 https://makina-corpus.com/blog/meti ...

  6. PHP SOAP模块的使用方法:NON-WSDL模式

    PHP SOAP扩展可以帮助我们很轻松的实现web service服务,在PHP的SOAP扩展中主要有两种操作模式:WSDL模式和NON-WSDL模式,前者通过使用WSDL文件名作为参数,并从 WSD ...

  7. 成长日记--记录在WB的第一个项目。

    具体为什么跑去外包,只能说自己太水了,或者太懒了,都不好好投简历,也没入这个坑过,如果有想去外包的,除非钱给到市场价的1.5倍以上,否则别考虑了. 项目是国内第一做通信公司的,从具体的需求说起比较好, ...

  8. apache源码编译安装

    源码安装apche 下载apache的源码包文件 访问http://mirror.bit.edu.cn/apache/httpd/,复制如下gz文件的链接地址,并使用wget下载到本地 wget -P ...

  9. 嵌入式(C)笔试题

    1 读程序段,回答问题 (a) int main(int argc,char *argv[]) { int c=9,d=0; c=c++%5; d=c; printf("d=%d\n&quo ...

  10. linux下创建带password的用户

    一直在做实验室linuxserver的账号管理系统,现阶段是用户申请后我这边收到邮件,然后手动创建,这个略显麻烦,打算全然做成自己主动化的.用户申请后,我直接在管理界面点击批准就可以创建用户,同一时候 ...