10191 - Longest Nap

All about problems in Volume CI. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Re: 10191 - Longest Nap

Postby plamplam » Thu Jul 21, 2011 3:18 pm

Quite a cushy problem I must say.

There won't be any cases like
0 (Although it is a valid case IMAO)
(Trust me, my program prints garbage if n is 0, I still got Accepted).
Also, there is always going to be a single space between the starting and finishing time.
And appointment times doesn't overlap, I'm not sure if there is going to be an empty string after the end time, because my program just ignores everything after the finishing time. (I used gets and later separated starting and ending time)

Nevertheless, try this set if you get Wrong Answer :) :

Code: Select all
3
10:07 12:19 Football game
13:11 16:17 Why why why me?
16:59 17:30 Nanananna Music :D
1
12:00 16:00 Burdens up my ass
1
12:00 15:59           Miserable At Best
3
15:00 17:00 Hey, don't blow a fuse!
13:00 15:00 Codeforces contest!!
10:00 11:00 Dinner time....yeaa :D
3
13:00 14:00 Shower
14:00 15:00 Again Shower!
15:00 16:00 Not again :(
3
10:00 10:12 Good night mommy
13:01 13:14 Masturbating time/Quickie
14:10 15:57 Secret Research!
1
13:59 14:01 Do you know what this means?
1
13:58 14:01 Got a buck to spare dude?
9
17:57 17:59     Aaaaaaaaaaaaaaaa
13:13 13:58 Break time :D
10:05 10:15 Solving this problem was a bummer(jk)
15:25 16:25 uhunt problem solving
14:21 15:01 ........
10:20 11:01 Pandora Radio()
16:30 17:00 Reading (I need more time to cram for the test).
12:00 12:37 Can't decide what to do, I guess I'll just take a nap.
17:30 17:54 Late night porn
4
14:47 17:04 Popcorn mmmm.....
10:16 11:05 I still watch popeye(Please don't tell anyone)
17:30 17:50 Cleaning up the mess
13:18 14:01 Whoaa
2
16:00 18:00 Shit happened today
11:59 14:01 I tried for 4 hours, but still couldn't solve problem 10191


Code: Select all
Day #1: the longest nap starts at 12:19 and will last for 52 minutes.
Day #2: the longest nap starts at 10:00 and will last for 2 hours and 0 minutes.
Day #3: the longest nap starts at 15:59 and will last for 2 hours and 1 minutes.
Day #4: the longest nap starts at 11:00 and will last for 2 hours and 0 minutes.
Day #5: the longest nap starts at 10:00 and will last for 3 hours and 0 minutes.
Day #6: the longest nap starts at 10:12 and will last for 2 hours and 49 minutes.
Day #7: the longest nap starts at 10:00 and will last for 3 hours and 59 minutes.
Day #8: the longest nap starts at 14:01 and will last for 3 hours and 59 minutes.
Day #9: the longest nap starts at 11:01 and will last for 59 minutes.
Day #10: the longest nap starts at 11:05 and will last for 2 hours and 13 minutes.
Day #11: the longest nap starts at 10:00 and will last for 1 hours and 59 minutes.
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
User avatar
plamplam
Experienced poster
 
Posts: 151
Joined: Fri May 06, 2011 11:37 am

Re: 10191 - Longest Nap

Postby warheadshot » Tue Feb 07, 2012 10:36 am

Hi, Why I get WA? Thx in advance.

Code: Select all
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
 
char line[257];
int a[100],b[100];int pos=-1;
 
int brek(int x){
        int nn=0,n2=0;int pos1=-1;
        for(int i=0;i<=x;i++){
                int mm=8000,m2=8000;
                for(int j=1;j<=x+1;j++){
                        if(a[j]-b[i]<0){continue;}
                        m2=min(mm,a[j]-b[i]);
                        if(m2!=mm){mm=m2;pos1=b[i];}
                }
                n2=max(nn,mm);
                if(n2!=nn){nn=n2;pos=pos1;}
        }
        return(nn);
}
 
int main(){
        int s,cc,cont=0;int q,w,e,r;
        while(scanf("%d\n",&s)==1){
                cont++;
                a[0]=600;b[0]=600;
                for(int ii=0;ii<s;ii++){
                        gets(line);
                        sscanf (line, "%d:%d %d:%d", &q, &w, &e, &r);
                        a[ii+1]=q*60+w;
                        b[ii+1]=e*60+r;
                }
                a[s+1]=1080;b[s+1]=1080;cc=brek(s);
                cout<<"Day #"<<cont<<": the longest nap starts at ";
                if(pos==-1){cout<<"18:00 and will last for 0 minutes.\n";continue;}
                cout<<pos/60<<":";
                if(pos%60<10){cout<<"0"<<pos%60<<" and will last for ";}else{cout<<pos%60<<" and will last for ";}
                if(cc<60){cout<<cc<<" minutes.\n";continue;}
                cout<<cc/60<<" hours and "<<cc%60<<" minutes.\n";continue;
                               
        }
}
warheadshot
New poster
 
Posts: 2
Joined: Tue Feb 07, 2012 10:20 am

Re: 10191 - Longest Nap

Postby invadrFlip » Wed Aug 15, 2012 7:09 pm

Thank you plamplam! Your test input saved me. I'm using java and was having difficulty printing the minutes in the hh:mm format when napStart % 60 was less than 10.
My code would print 14: 1 instead of 14:01. Apparently, my initial solution made it worse. Your test input found this problem while all before would not. Thanks.

Any ideas on how to format these strings in the future using java?
invadrFlip
New poster
 
Posts: 8
Joined: Fri Aug 10, 2012 7:48 am

Previous

Return to Volume CI

Who is online

Users browsing this forum: Exabot [Bot] and 0 guests