1193 Eason
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 样例输出2 2 |
||
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的更多相关文章
- bzoj 1193 贪心
如果两点的曼哈顿距离在一定范围内时我们直接暴力搜索就可以得到答案,那么开始贪心的跳,判断两点横纵坐标的差值,差值大的方向条2,小的条1,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...
- bzoj 1193
http://www.lydsy.com/JudgeOnline/problem.php?id=1193 大范围贪心,小范围宽搜. 膜拜大神 http://blog.csdn.net/u0129155 ...
- bzoj 1193 贪心+bfs
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2015 Solved: 914[Submit][Statu ...
- 1193: [HNOI2006]马步距离
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2027 Solved: 915[Submit][Statu ...
- 九度OJ 1193:矩阵转置 (矩阵计算)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1673 解决:1132 题目描述: 输入一个N*N的矩阵,将其转置后输出.要求:不得使用任何数组(就地逆置). 输入: 输入的第一行包括一个 ...
- BZOJ 1193 [HNOI2006]马步距离:大范围贪心 小范围暴搜
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1193 题意: 给定起点(px,py).终点(sx,sy).(x,y < 100000 ...
- hpuoj 1193: Interval
Interval [STL.双指针.二分] 题目链接 http://acm.hpu.edu.cn/problem.php?id=1193 或者 题目链接 http://acm.nyist.net/Ju ...
- Vijos 1193 扫雷 【动态规划】
扫雷 描述 相信大家都玩过扫雷的游戏.那是在一个n*n的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”任过流行起了一种简单的扫雷游戏,这个游戏规则和扫雷一样,如果某个格子没有雷,那么它 ...
- JOBDU 1193 矩阵转置
啊!!!这道题目今天竟然写错了!!!这道题目巨坑,说不能用数组,结果竟然是用数组做的,吐血!!! 看的所有有关博文,都是用数组做的,晕倒!真的出题人有毛病,出这种题,又不限制运行!!! 以后再遇到这种 ...
随机推荐
- JOSN快速入门
1.JSON介绍 (1)JSON是一种与开发语言无关的,轻量级的数据格式,全称 JavaScript Object Notation,易于阅读和编写,语言解析和生产 (2)JSON数据类型表示 数据 ...
- Spannable对textview首行缩进的设置
1.创建Spannable对象 SpannableString contentSpan = new SpannableString(data.getBusinessTitle()); 2.设置文本缩进 ...
- 前端压缩图片,前端压缩图片后转换为base64.
今天利用一上午研究了一下前端如何将5m左右的照片转换base64大小为 100k以内! 有两个链接:https://www.cnblogs.com/007sx/p/7583202.html :http ...
- 路飞学城Python-Day1
1.什么是编程?编程就是写代码,代码是计算机理解的语言,编程就是通过计算机理解的语言实现一些事件,计算机能理解的就是二进制,就是0和1的两个值计算机底层是电路,如何表达0和1?就像灯只能表示开灯和关灯 ...
- window下搭建Python3.7+selenium3.1.1+pycharm环境
1.安装Python3.7 1.1 下载 Python并安装 Python3.5 (勾选上 Add Python3.7 to PATH) 点击 Install Now,安装完成后将python路径加 ...
- (转)RestFul 无状态的一点认识
今天早上在Yahoo的邮件列表里看到一篇颇有意思的讨论,标题为RESTful vs. unRESTful: Session IDs and Authentication(51CTO编者注:意为REST ...
- 斗地主算法的设计与实现(一)--项目介绍&如何定义和构造一张牌
大学期间,我在别人的基础上,写了一个简易的斗地主程序. 主要实现了面向对象设计,洗牌.发牌.判断牌型.比较牌的大小.游戏规则等算法. 通过这个斗地主小项目的练习,提高了我的面向对象设计能力,加深了对算 ...
- python学习--导入自己的包
定义一个自己的方法包: def myFunc(x): if x > 10: return x else: return -x 在需要的地方导入包: # 导入自定义的方法包 from learn ...
- 【BZOJ 1196】[HNOI2006]公路修建问题
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二分最后选的边中的最大值是多少. mid 则所有边权小于等于mid的边都可以用了. 那么我们要怎么选择呢? ->优先选择一级的 ...
- OpenStack-API开发
介绍两种OpenStack-API(Java版)--jcoulds && openstack4j Jclouds 1.介绍 jclouds -该API提供云计算环境的可移植抽象层以及云 ...