现在的位置: 首页 > 综合 > 正文

poj2210!

2014年09月24日 ⁄ 综合 ⁄ 共 2895字 ⁄ 字号 评论关闭
/*Metric Time
Time Limit: 1000MS  Memory Limit: 65536K 
Total Submissions: 2598  Accepted: 804 

Description

The Metric Time is one of the most important points of PSOS Election Programme. The Time can be much easier calculated in operating systems. 
These systems are then more stable, which meets the main goal of the Party. 

<span style="color:#ff0000;">The length of one day is the same as with the "classic" time.</span> The day is divided into 10 metric hours, each of them into 100 metric minutes, 
and each minute into 100 metric seconds. 10 metric days form one metric week, 10 metric weeks give one metric month, 10 metric months are called 
metric year. It is obvious this Metric Time is much better than the classic one. 

Some opponent parties often complain that the Metric Time has also some drawbacks. First of all, it would be very difficult to change to 
the new time. PSOS Chairman decided to solve these problems all at once. He plans to publish a freeware utility which will be able to convert 
between the time formats. Your goal is to write one half of this utility, the program which converts classic time to Metric Time. Metric hours, 
metric minutes, and metric seconds are counted starting with zero, as usual. Metric days and metric months start with one. There exist metric year
 zero. The metric seconds should be rounded to the nearest smaller integer value. Assume that 0:0:0 1.1.2000 classic time is equal to 0:0:0 1.1.0
  Metric Time. 

Note that the classic year is leap, if it is an integer multiple of 4. The only exception are years divisible by 100 - they are leap only if they 
are an integer multiple of 400. For example, leap years are 1996, 2400, and 2000; leap years are not 1900, 2300, 2002. 

Input

At the first line there is a positive integer N stating the number of assignments to follow. Each assignment consists of exactly one line in the 
form "hour:minute:second day.month.year" which is the date in the classic form (usual in most of European countries). The date is always valid,
 2000 <= year <= 50000. 
Output

The program must print exactly one line for each assignment. The line should have the form "mhour:mmin:msec mday.mmonth.myear" which is the Metric
 Time equal to the specified classic time. 
Sample Input

7
0:0:0 1.1.2000
10:10:10 1.3.2001
0:12:13 1.3.2400
23:59:59 31.12.2001
0:0:1 20.7.7478
0:20:20 21.7.7478
15:54:44 2.10.20749

Sample Output

0:0:0 1.1.0
4:23:72 26.5.0
0:8:48 58.2.146
9:99:98 31.8.0
0:0:1 100.10.2000
0:14:12 1.1.2001
6:63:0 7.3.6848

Source

CTU FEE Local 1998
*/
#include<stdio.h>
int leap(int x)
{
	if( (x % 400 == 0) || ( x % 100 != 0 && x%4 == 0))
	return 1;
	return 0;
}
int a[48110];
int main()
{
	int n, i, y1, y2, m1, m2, d1, d2, h1, h2, mi1, mi2, s1, s2, sec;
	scanf("%d", &n);
    a[0] = 0; 
    for(i = 2000; i <= 50000; i++)
	{
          a[i-1999] = a[i-2000];         
	      if( leap(i) )
			a[i-1999]++;
	}
	while(n--)
	{
		int day ;
		scanf("%d:%d:%d %d.%d.%d", &h1, &mi1, &s1, &d1, &m1, &y1);
		day = d1 - 1;
		day += ( ( 365 * (y1 - 2000) ) + a[y1-2000] );
		for(i = 1; i < m1; i++)
		{
			if( i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) 
			day += 31;
			else
			day += 30;
		}
		if( m1 > 2)
        {
            if(leap(y1))
            day -= 1;
            else
            day -= 2;
        }
		y2 = day / 1000;
		day %= 1000;
		m2 = 1 + day / 100;
		day %= 100;
		d2 = 1 + day;
		sec = 0;
		sec = (int)((h1 * 3600 + mi1*60 + s1) / 0.864); 
		h2 = sec / 10000;
		sec %= 10000;
		mi2 = sec / 100;
		sec %= 100;
		s2 = sec;
		printf("%d:%d:%d %d.%d.%d\n", h2, mi2, s2, d2, m2, y2);
	}
	return 0;	
}

题意:将正常的日历转换为题目要求的特殊的日历。

本题的切入点就是 正常的日历 和 特殊的日历的 天数单位时长是一样的,因此将时分秒与年月日分开计算!

其次就是计算天数时需要的优化,例如瑞年的优化,尽量降低时间复杂度,避免TLE。

抱歉!评论已关闭.