MZ test17# NOIP模拟题 # T1 第1题 时间计算(heaven.pas/cpp)[key.模拟]

第1题  时间计算(heaven.pas/cpp)

 

【问题描述】

有一天,我做了个梦,梦见我很荣幸的接到了猪八戒的邀请,到天宫陪他吃酒。我犹豫了。天上一日,人间一年啊!当然,我是个闲人,一年之中也没有多少时日是必须在人间的,因此,我希望选一个最长的空闲时间段,使我在天上待的时间尽量长。记住,今年是4000年。天上一天也是24小时,每小时60分,每分60秒。

 

【输入数据】

输入文件的第一行是一个非负整数 N,表示4000年中必须呆在人间的天数,以下共N行,每行两个用空格隔开的正整数,即日期(月,日),输入文件保证无错误,日期无重复。

 

【输出数据】

输出文件仅有一行包含一个非负整数,即在天上的时间(四舍五入精确到秒)。

 

【样例输入】heaven.in

2

3 8

12 2

 

【样例输出】heaven.out

63266

 



#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
void init(){
	freopen("heaven.in","r",stdin);
	freopen("heaven.out","w",stdout);
}
int n;
int month[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
struct date{
	int m,n;
}d[500];
bool cmp(date a,date b){
	return a.m==b.m?a.n<b.n:a.m<b.m;
}
int cont(date a,date b){
	if(a.m==b.m)return b.n-a.n-1;
	else{
		int ans=0;
		while(a.m<b.m){
			ans+=month[a.m]-a.n;
			a.m++;
			a.n=0;
		}
		ans+=b.n-1;
		return ans;
	}
}

int main(){
	init();
	scanf("%d",&n);
	d[1].m=1,d[1].n=0;
	d[n+1].m=12,d[n+1].n=32;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&d[i].m,&d[i].n);	 
	}
	sort(d,d+n+2,cmp);
	int Max=-1;
	for(int i=1;i<=n+1;i++){
		Max=max(Max,cont(d[i-1],d[i]));
	}
	printf("%.0lf",((24*60*60/366.0)*(Max)));
	return 0;
}


你可能感兴趣的:(模拟)