zoj 3131 Digital Clock
来源:互联网 发布:人工智能伏羲觉醒电影 编辑:程序博客网 时间:2024/06/06 02:21
/*看到这题首先想起来模拟but。。。超时。。。然后想起来打表查找最先是把所有秒数都存起来开了一个86400的数组然后把可以被3整除的赋值为1其余为0然后只需要查找区间中1的个数即可结果。。。TLE。。。后来看题解发现自己原来做了那么多的无用功先是写了一个test()查出一共有28800个满足题意的钟表数然后写入数据的时候就抛弃不符合的数完成提交AC */#define LOCAL#include<iostream>#define N 28800using 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;}