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 矩阵转置
啊!!!这道题目今天竟然写错了!!!这道题目巨坑,说不能用数组,结果竟然是用数组做的,吐血!!! 看的所有有关博文,都是用数组做的,晕倒!真的出题人有毛病,出这种题,又不限制运行!!! 以后再遇到这种 ...
随机推荐
- *hiho 1475 - 数组拆分,dp,由N^2降到NlogN
题目链接 描述 小Ho得到了一个数组作为他的新年礼物,他非常喜欢这个数组! 在仔细研究了几天之后,小Ho成功的将这个数组拆成了若干段,并且每段的和都不为0! 现在小Ho希望知道,这样的拆分方法一共有多 ...
- Glidar测试安装
在上一篇随笔中,我们完成了对Glidar 仿真器的概念层面的认识.接下来,我们将着手对该该仿真器进行安装测试. 1 依赖库的安装 安装环境为Windows 7 64位+Ubuntu14.04 LTS的 ...
- Caffe Loss分析
Caffe_Loss 损失函数为深度学习中重要的一个组成部分,各种优化算法均是基于Loss来的,损失函数的设计好坏很大程度下能够影响最终网络学习的好坏.派生于 \(LossLayer\),根据不同的L ...
- 数字游戏(string的sort的应用)
题目描述 牛牛举办了一场数字游戏,有n个玩家参加这个游戏,游戏开始每个玩家选定一个数,然后将这个数写在纸上(十进制数,无前缀零),然后接下来对于每一个数字将其数位按照非递减顺序排列,得到新的数,新数的 ...
- map、栈————下一个更大的元素(待定,栈解法学习中)
方法一 先遍历nums2,将每个元素后面第一个大的元素一起存入到map中,然后在遍历nums1,在map中找到. class Solution { public: vector<int> ...
- 路飞学城-Python开发-第二章
''' 数据结构: menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村':{ '爱奇艺':{}, '汽车之家' ...
- WebKit.NET-0.5简单应用(2)——音量解决方案
查找WebKit.NET相关文档,没有找到音量控制解决方法.换思路进行解决,尝试用Win32 API进行解决 [DllImport("winmm.dll")] public sta ...
- Spring boot配置404、500页面
Spring boot 配置404页面很简单,如果你访问的url没有找到就会出现spring boot 提示的页面,很明显Spring boot不用配置就可以显示404页面了. 在template下创 ...
- unity Android在streamingAssets路径下文件无法读取的的解决方法
unity Android在streamingAssets路径下文件,有时候plugin下的.jar或者.so无法直接读取: 解决方法之一,拷贝至其他路径: #if UNITY_ANDROID str ...
- 题解 P3834 【【模板】可持久化线段树 1(主席树)】
可持久化线段树的前置知识是权值线段树,但是你不学也没有太大的关系因为思想不是很难理解. 可持久化线段树支持历史记录查询,这是它赖以解题的方法. 在本题中思路是建立n颗线段树,然后对于每次询问,考虑其中 ...