To the Heavenly House-last minute ac!!!

Source: Internet
Author: User

Question C: Guest time limit: 1 Sec memory limit: MB
Submitted: 26 Resolution:
Submitted State [Discussion Version] Topic Description One day, I had a dream, dreamed I was honored to receive the invitation of pig, to the Heavenly Palace accompany him to eat wine. I hesitated. One day in the sky, a year on earth! Of course, I am an idler, there is not much time in a year is to be in the world, therefore, I would like to choose a maximum free time period, so that I stay in the sky as long as possible. Remember, this year is 4,000 years. The sky is also 24 hours a day, 60 minutes per hour, 60 seconds per minute. Enter the first line is a non-negative integer N, indicating the number of days that must stay in the world in 4000, the following total N lines, each line two spaces separated by a positive integer, that is, the date (month, day), the input guarantee error-free, date no duplicates. The output has only one row containing a non-negative integer, which is the time in the sky (rounded down to seconds). Sample input
23 812 2
Sample output
63266

problem-solving ideas: today is an unforgettable day, experience a word, not until the last moment must not give up! Last minute AC through!
In a situation where two adjacent dates are within one months, my algorithm calculates errors.
The way you think of yourself is often quite redundant and prone to error, or your own skill is not enough.
When choosing an algorithm, you should choose simple and error-prone lines.
It is not necessary to discuss the situation in a piece of discussion, but to pay attention to merging the same situations.
Code:
#include <iostream>#include<cstdio>#include<algorithm>using namespaceStd;typedefstructnode{intmonth; intDay ;}; Node a[370];intCMP (node A,node b) {return(A.month<b.month) | | (a.month==b.month&&a.day<b.day);}intMain () {intN; intmaxx=0; intdaycount[370]={0}; intmonthday[ -]={0, to, in, to, -, to, -, to, to, -, to, -, to}; scanf ("%d",&N); if(n==0) {printf ("86400\n"); return 0; }    if(n==366) {printf ("0\n"); return 0; }     for(intI=0; i<n;i++) {scanf ("%d%d",&a[i].month,&a[i].day); } sort (A,a+n,cmp);  for(intI=0; i<n+1; i++){        if(i==0){             for(intj=1; j<a[i].month;j++) {Daycount[i]+=Monthday[j]; } Daycount[i]+=a[i].day-1; }        if(i==N) {             for(intj=a[i-1].month+1; j<= A; j + +) {Daycount[i]+=Monthday[j]; } Daycount[i]+ = (monthday[a[i-1].month]-a[i-1].day); }        if(i!=0&&i!=n&&a[i].month!=a[i-1].month) { for(intj=a[i-1].month+1; j<a[i].month;j++) {Daycount[i]+=Monthday[j]; } Daycount[i]+ = (monthday[a[i-1].month]-a[i-1].day); Daycount[i]+=a[i].day-1; }        if(i!=0&&i!=n&&a[i].month==a[i-1].month) {//This case is dropped when done! Daycount[i]+=a[i].day-a[i-1].day-1; } Maxx=Max (Daycount[i],maxx); }    Doublesecond=maxx*86400*1.0/366; printf ("%.0lf\n", maxx*86400*1.0/366); return 0;}

To the Heavenly House-last minute ac!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.