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 1 100 1 1000000 0 0 样例输出2 2 28 36 215488 737856 |
||
Sample Input |
||
Sample Output |
||
Source |
解题:暴力或者数位dp乱搞
先上暴力的解法:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define INF 0x3f3f3f3f 15 #define pii pair<int,int> 16 using namespace std; 17 int ans[1000001],uu[1000001]; 18 void go(int dep,int cur,int step,bool like,bool ulike){ 19 if(step > dep || like && ulike) return; 20 ans[cur] = like; 21 if(!like && !ulike) uu[cur] = 1; 22 for(int i = step?0:1; i <= 9; ++i) 23 go(dep,cur*10+i,step+1,like||i == 3||i == 6,ulike||i == 4||i == 7); 24 } 25 int main(){ 26 go(6,0,0,false,false); 27 uu[1000000] = 1; 28 for(int i = 1; i < 1000001; ++i){ 29 ans[i] += ans[i-1]; 30 uu[i] += uu[i-1]; 31 } 32 int a,b; 33 while(scanf("%d %d",&a,&b),a||b){ 34 int tmp = ans[b]-ans[a-1]; 35 printf("%d %d\n",tmp,(b-a+1)-(uu[b]-uu[a-1])-tmp); 36 } 37 return 0; 38 }
View Code
写得比较挫,很多冗余计算。。。后来改了下,起码好看得多了
1 #include <cstdio> 2 int ans[1000001],uu[1000001],arr[] = {0,1,2,3,5,6,8,9},a,b; 3 bool check[10] = {false,false,false,true,false,true}; 4 void go(int dep,int cur,int step,bool like){ 5 if(step > dep) return; 6 if(like) ans[cur] = 1; 7 else uu[cur] = 1; 8 for(int i = step?0:1; i < 8; ++i) 9 go(dep,cur*10+arr[i],step+1,like||check[i]); 10 } 11 int main(){ 12 go(6,0,0,false); 13 uu[1000000] = 1; 14 for(int i = 1; i < 1000001; ++i){ 15 ans[i] += ans[i-1]; 16 uu[i] += uu[i-1]; 17 } 18 while(scanf("%d %d",&a,&b),a||b){ 19 int tmp = ans[b]-ans[a-1]; 20 printf("%d %d\n",tmp,(b-a+1)-(uu[b]-uu[a-1])-tmp); 21 } 22 return 0; 23 }
View Code
然后是数位dp
1 #include <cstdio> 2 #include <cstring> 3 int dp[10][2]; 4 void calc(char *str,int &x,int &y){ 5 bool xh = false,bxh = false; 6 int len = strlen(str); 7 static const int cnt[10] = {0,1,2,3,4,4,5,6,6,7}; 8 static const int cnt2[10] = {0,1,2,3,3,3,4,4,4,5}; 9 for(int i = x = y = 0; str[i+1]; ++i){ 10 int p = (str[i] > '3') + (str[i] > '6'); 11 if(!bxh){ 12 if(xh) x += cnt[str[i]-'0']*(dp[len-i-1][1]+dp[len-i-1][0]); 13 else{ 14 x += cnt[str[i]-'0']*dp[len-i-1][0] + p*dp[len-i-1][1]; 15 y += cnt2[str[i]-'0']*dp[len-i-1][1]; 16 } 17 } 18 if(str[i] == '4' || str[i] == '7') bxh = true; 19 if(str[i] == '3' || str[i] == '6') xh = true; 20 } 21 for(int i = 0; i <= str[len-1]-'0'; ++i){ 22 if(!xh && !bxh &&(i == 3 || i == 6)) ++x; 23 if(xh && !bxh && i != 4 && i != 7) ++x; 24 if(!bxh && !xh && i != 3 && i != 6 && i != 4 && i != 7) ++y; 25 } 26 } 27 int main(){ 28 dp[1][0] = 2; 29 dp[1][1] = 6; 30 for(int i = 2; i <= 6; ++i){ 31 dp[i][0] = (dp[i-1][0]<<3) + (dp[i-1][1]<<1); 32 dp[i][1] = 6*dp[i-1][1]; 33 } 34 char str[10]; 35 int a,b; 36 while(scanf("%d %d",&a,&b),a||b) { 37 int x,y,x1,y1; 38 sprintf(str,"%d",--a); 39 calc(str,x,y); 40 sprintf(str,"%d",b); 41 calc(str,x1,y1); 42 int tmp = x1 - x; 43 printf("%d %d\n",tmp,b-a-tmp-y1+y); 44 } 45 return 0; 46 }
View Code
转载于:https://www.cnblogs.com/crackpotisback/p/4213597.html
1193 Eason相关推荐
- mysql1193 HY000_[MySQL参数取值] Status取值ERROR 1193 (HY000): Unknown system_MySQL
bitsCN.com [MySQL参数取值] Status取值ERROR 1193 (HY000): Unknown system variable 'Innodb_buffer_pool_read_ ...
- C语言实验 圆周率1193,【圆周率】小数点后10000位,4个4个分,你能找到那些配对?...
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 4425 3223 4157 6233 6106 4250 6390 4975 0086 5627 1095 3591 9465 8975 1413 10 ...
- 信息学奥赛一本通 1193:吃糖果 | OpenJudge NOI 2.6 1944:吃糖果
[题目链接] OpenJudge NOI 2.6 1944:吃糖果 注:ybt 1193:吃糖果 页面打不开,可以在OpenJudge做该题. [题目考点] 1. 递推/递归 2. 搜索 [解题思路] ...
- 信息学奥赛一本通(1193:吃糖果)
1193:吃糖果 时间限制: 1000 ms 内存限制: 65536 KB 提交数: 3415 通过数: 2719 [题目描述] 名名的妈妈从外地出差回来,带了一盒好吃又精美的 ...
- 【MySQL】MySQL 8 ERROR 1193 (HY000): Unknown system variable ‘tx_isolation‘
1.背景 mysql> select @@tx_isolation; ERROR 1193 (HY000): Unknown system variable 'tx_isolation' mys ...
- BZOJ 1193: [HNOI2006]马步距离【贪心+搜索】
1193: [HNOI2006]马步距离 [题目描述] 传送门 [题解] 大范围贪心,然后小范围BFS,为了答案准确,尽量使这个小范围大,这题100就可以了. 代码如下 #include<que ...
- bzoj 1193: [HNOI2006]马步距离(贪心+BFS)
1193: [HNOI2006]马步距离 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2117 Solved: 953 [Submit][Sta ...
- [BZOJ 1193] 马步距离
Link:https://www.lydsy.com/JudgeOnline/problem.php?id=1193 Solution: 能立刻看出贪心算法,但发现在小数据时明显不适用 于是我们采取大 ...
- mysql 1193_登入phpMyAdmin提示#1193 - Unknown system variable 'lc_messages' | 小朱笔记
买的vps安装lnmp建站,登入数据库提示错误: SET lc_messages = 'zh_CN'; MySQL 返回:#1193 - Unknown system variable 'lc_mes ...
- mysql 5.5升级5.6报错:ERROR 1193 (HY000) at line 84: Unknown system variable 'have_csv'
首先登陆数据库没有问题呀,但是有报错, 文本显示: ERROR 1193 (HY000) at line 84: Unknown system variable 'have_csv' ERROR 10 ...
最新文章
- 追求极致的AI·OS——AI·OS引擎平台
- CPU也支持AI加速,英特尔发布第3代至强处理器,推理速度提升80%,阿里腾讯云都在用...
- 如何在GitHub上大显身手?
- QT的QScriptEngineDebugger类的使用
- 科技情报研究所工资_我们所说的情报是什么?
- 华为发布基于自进化AI的HiSec Insight安全态势感知系统
- 消息称Uber正洽谈出售旗下自动驾驶部门ATG给Aurora
- oracle中正则表达式相关函数regexp_like简介
- Redis学习总结(14)——图解redis五种数据结构底层实现(动图版)
- 小学计算机课评价方案,小学信息技术课堂评价方法的研究
- Spring4+Springmvc+quartz实现多线程动态定时调度
- 微信小程序商机_微信小程序怎么用?有哪些商机?
- 【渝粤题库】 陕西师范大学 210021 学前儿童健康教育 作业(专升本)
- macOS Big Sur:快速入门的50个使用技巧
- Python优化算法01——差分进化算法
- 首次!中国移动在Nature 杂志子刊 Nature Electronics发表5G高能效通信技术文章
- 漫画:996的本质是什么?
- 史上最暴强老纳和师太-----全集!
- Zbar+ROS+opencv二维码识别与定位研究(一)
- Cannot run program‘C:\Anaconda3\envs\...\python.exe’(in directory):CreateProcess error=2,系统找不到指定文件
热门文章
- linux crond定时任务,Linux之定时任务Crond使用
- 蓄水池采样算法的python实现_蓄水池采样算法-Reservoir Sampling
- dfuse for EOSIO v0.1.0-beta4 版本更新说明
- kubectl rollout restart 命令“unkonw command“
- 智能计算系统课程笔记05:编程框架机理
- Java 10大骚操作写法,亮瞎boss的双眼!
- ipad接受airdrop_如何在iPhone,iPad和Mac上使用AirDrop即时共享文件
- rd640 linux raid,联想服务器rd640如何设置raid 1
- itunes计算机无法启动,电脑怎么打开itunes
- 英文商务邮件开场白结尾