ZOJ.3131 Digital Clock【打表】 2015/10/11
来源:互联网 发布:dvd播放软件 tn 编辑:程序博客网 时间:2024/05/16 15:04
Digital clocks usually show the time in the form hh:mm:ss, where hh is a number between 00 and 23, and both mm and ss are numbers between 00 and 59. Removing the colons from hh:mm:ss will result in an integer hhmmss, which is called aclock integer. For example, the clock integer of 17:05:13 is 170513 and the clock integer of 00:07:37 is 737.
You are given a time interval and you are to determine the number of clock integers in it that are multiples of 3. A time interval will be given by specifying its start and end time. For example, the time interval [00:59:58, 01:01:24] has a total of 1+1+60+25=87 clock integers, namely, 5958, 5959, 10000 through 10059, and 10100 through 10124. How many of them are multiples of 3?
Note that a time interval that includes midnight may have a start time greater than its end time, as in [22:47:03, 01:03:24]. You may assume that a time interval is at least one second long and shorter than 24 hours.
Write a program that can determine the number of multiples of 3 in a time interval.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test casesT is given in the first line of the input. Each test case consists of a single line that contains the start time and end time of a time interval, which are separated by a single space.
Output
Your program is to write to standard output. Each test case outputs exactly one line. Print the number of multiples of 3 among the clock integers in the time interval. The following shows a sample input with three test cases and its output.
Sample Input
300:59:58 01:01:2422:47:03 01:03:2400:00:09 00:03:37
Sample Output
29272770
Source: Asia Regional Contest Seoul 2006
打表做,记录从0:00:00到当前时刻符合要求的时刻的数量,如果是第一天到第二天,分两次求
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int times[300000];void init(){ memset(times,0,sizeof(times)); int i,j,k; times[0] = 1; for( i = 1 ; i <= 235959 ; ++i ){ if( i % 100 >= 60 || i % 10000 >= 6000 ) times[i] = -1; else{ if( i % 10000 == 0 ){ times[i] = times[i-4041]; if( i % 3 == 0 ) times[i]++; } else if( i % 100 == 0 ){ times[i] = times[i-41]; if( i % 3 == 0 ) times[i]++; } else{ times[i] = times[i-1]; if( i % 3 == 0 ) times[i]++; } } }}int main(){ int h,h1,h2,m,m1,m2,s,s1,s2; int t,ans; int ret1,ret2; init(); cin>>t; while(t--){ scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2); ret1 = h1 * 10000 + m1 * 100 + s1; ret2 = h2 * 10000 + m2 * 100 + s2; if( ret1 > ret2 ){ ans = times[235959] - times[ret1]; ans += times[ret2]; } else ans = times[ret2] - times[ret1]; if( ret1 % 3 ==0 ) ans++; cout<<ans<<endl; } return 0;}
- ZOJ.3131 Digital Clock【打表】 2015/10/11
- zoj 3131 Digital Clock
- zoj 3131 Digital Clock
- ZOJ 3131 Digital Clock
- ZOJ3131 Digital Clock
- QT实现Digital Clock
- hdu1404 Digital Deletions SG打表
- UVALive 2037 Digital Rivers 【打表&二分】
- zoj3131 Digital Clock(2)
- 【QT 教程】Digital Clock Example
- Digital Clock 数论水题
- UVALive - 6269 Digital Clock 模拟
- zoj 3878【打表模拟】
- Clock ZOJ 3313
- zoj 1476 Weird Clock
- ZOJ 1122 Clock
- zoj 3191 Strange Clock
- ZOJ 3191 Strange Clock
- Windows高精度计时
- [BZOJ1218] [HNOI2003]激光炸弹
- leetcode31
- spring 注解配置bean2
- Binary Tree Paths
- ZOJ.3131 Digital Clock【打表】 2015/10/11
- Collections结合Comparator实现对列表的快速排序
- 17.1.1.7 Setting Up Replication with New Master and Slaves
- 使用swfupload进行异步文件上传(java版)
- ZOJ 3903 Ant(公式)
- hdu 5463 Clarke and minecraft(水)
- 抽奖系统
- 表达式生成问题
- svn提交自动更新服务器端web项目测试站点(使用svn的hooks实现)