不要62
来源:互联网 发布:淘宝达人在哪看 编辑:程序博客网 时间:2024/05/02 00:41
不要62
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 93 Accepted Submission(s) : 33
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。
不吉利的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。
Input
Output
Sample Input
1 1000 0
Sample Output
80/*这个虽然能运行但在oj上时间受限*/
#include<stdio.h>int a[1000000];int main(){
int n,m;//a[10000] while(scanf("%d%d",&n,&m)) { int i,j=0,b,num=0,s; if(n==0&&m==0) break; s=m-n+1; for(i=n;i<m;i++) { int h=0; a[j]=i; while(a[j]) { b=a[j]%10; if(b==4) { num++;break; } if(b==2) h=1; if(h==1&&b==6) { num++; break; } a[j]=a[j]/10; } j++; } printf("%d\n",s-num); } return 0;}
/*微调但还是超时*/
#include<stdio.h>//int a[1000000];int main(){
int n,m;//a[10000] while(scanf("%d%d",&n,&m)) { int i,j=0,b,num=0,s; if(n==0&&m==0) break; s=m-n+1; for(i=n;i<m;i++) { // int h=0; //a[j]=i; b=i; //while(a[j]) while(b) { /*b=a[j]%10; if(b==4) { num++;break; } if(b==2) h=1; if(h==1&&b==6) { num++; break; } b=a[j]%100; if(b==62) { num++; break; }*/ if(b%10==4||b%100==62) { num++; break; } b=b/10; } } printf("%d\n",s-num); } return 0;}
要用打表法,先处理从1到1000000的所有数据,将含4或62的标记出来,然后再输入n与m,遍历n到m之间的数看是否是标记过的,刚开始有点不理解,为什么这种处理从1到1000000所有数的方法会比n到m的方法需要的时间小,后来想了想可能是这样的,打表是在输入数据之前,也就是之后的无论多少组输入数据都不用再进行每个数的判断,直接可以应用表,而且hdoj上的处理时间应该是指从输入数据到输出结果直接之间的时间,所以不会再超时了。
#include<iostream>#include<cstring>using namespace std;int main(){ int i,b,c; bool a[1000000]; memset(a,0,sizeof(a));
for(i=1;i<1000000;i++) { int n,m; n=m=i; while(n>0) { if(n%10==4||n%100==62) a[m]=1; n=n/10; } } while(cin>>b>>c&&(b||c)) { int num=c-b+1; for(i=b;i<=c;i++) if(a[i]==1) num--; printf("%d\n",num); } return 0;}
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- 不要62
- OFBIZ的页面风格
- java函数--03
- Android SwipeRefreshLayout 官方下拉刷新控件介绍
- 文章标题
- centOS 大量TIME_WAIT 的处理
- 不要62
- 价格和价格规则
- 我的工作笔记开篇简介
- 花生壳端口映射——花生壳+visiualSVN实现外网访问局域网内的SVN(一)
- jQuery ui datepicker 日历转中文
- php基础
- oracle本地连接虚拟机数据库
- ofbiz tax
- 【从零单排之微软面试100题系列】19之Fibonacci数列