zoj 3131 Digital Clock

/* 看到这题首先想起来模拟 but。。。超时。。。 然后想起来打表查找 最先是把所有秒数都存起来 开了一个86400的数组然后把可以被3整除的赋值为1 其余为0 然后只需要查找区间中1的个数即可 结果。。。TLE。。。 后来看题解发现自己原来做了那么多的无用功 先是写了一个test()查出一共有28800个满足题意的钟表数 然后写入数据的时候就抛弃不符合的数 完成提交 AC */ #define LOCAL #include<iostream> #define N 28800 using namespace std; int t[N]; int main() { #ifdef LOCAL freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int count=0,h,m,s,n,i,start,end; string a,b; for(h=0;h<24;h++) //打表 { for(m=0;m<60;m++) { for(s=0;s<60;s++) { if((h/10+h%10+m/10+m%10+s/10+s%10)%3==0) t[count++]=h*10000+m*100+s; } } } while(cin>>n) //主体部分 { while(n--) { cin>>a>>b; start=((a[0]-'0')*10+a[1]-'0')*10000+((a[3]-'0')*10+a[4]-'0')*100+(a[6]-'0')*10+a[7]-'0'; end=((b[0]-'0')*10+b[1]-'0')*10000+((b[3]-'0')*10+b[4]-'0')*100+(b[6]-'0')*10+b[7]-'0'; count=0; if(start<end) { for(i=0;i<N;i++) if(t[i]>=start&&t[i]<=end) count++; } else { for(i=0;i<N;i++) if(t[i]<start&&t[i]>end) count++; count=28800-count; } cout<<count<<endl; } } return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值