HDU 4883 Tiankeng ' s Restaurant

Source: Internet
Author: User

Tiankeng ' s Restaurant

Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 1616 Accepted Submission (s): 580


problem DescriptionTiankeng manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to has meal because of its delicious dishes. Today n Groups of customers come to enjoy their meal, and there is Xi persons in the ith group in sum. Assuming that all customer can own only one chair. Now we know the arriving time STi and departure time EDi for each group. Could Tiankeng Calculate the minimum chairs he needs to prepare so that every customer can take a seat when Arriv ing the restaurant? 
InputThe first line contains a positive integer T (t<=100), standing for T test cases in all.

Each cases has a positive integer n (1<=n<=10000), which means n groups of customer. Then following n lines, each line there was a positive integer Xi (1<=xi<=100), referring to the sum of the number of The ith group people, and the arriving time STi and departure time Edi (the time format is hh:mm, 0<=hh<24, 0<=mm& LT;60), Given that the arriving time must be earlier than the departure time.

Pay attention if a group of people arrive at the restaurant as soon as a group of people leaves from the restaurant , then the arriving group can is arranged to take their seats if the seats is enough.
 
Outputfor each test case, the output of the minimum number of chair is Tiankeng needs to prepare. 
Sample Input
226 08:00 09:005 08:59 09:5,926 08:00 09:005 09:00 10:00
 
Sample Output
116
 
SourceBestcoder Round #2   Test Instructions:          The question is let's enter a number, which represents how many cases, Then the first line of each case input m for a m group of guests to come, and then enter M line, each line enter the number of benches required for this group and the start time and end time, to find out the number of bench required for this case!   Thinking:        by asking for each moment the number of bench required, and then compare to find the biggest is the maximum value! (In order to find the number of bench required at each moment at the same time to find out the maximum value), the specific code:  the first time the wrong idea: 
The wrong IDEA!!!!!! (Spend two hours did not change the mistake, the original thinking wrong)//1-2:2 1.5-3:3 2-4:4//with this thinking, you have to use 9 bench, but in fact 7 on the line, so the idea has a problem @@! 1! Bench problem is to consider the interval overlap problem, and Nanyang 14 venue arrangement, Hangzhou Electric 2037 this summer holiday not AC this question is not the same,//These two is to seek the number of overlapping interval is the most problem, two this problem is to ask overlap interval, completely different, see// Do not overlap The interval is to think about the venue arrangement and this summer holiday does not AC, when see overlap interval problem, consider the bench problem! #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include < Algorithm>using namespace std;struct Node {int num;int t1;int t2;} A[10005];int CMP (node U,node v) {if (U.T2==V.T2) return U.num>v.num;return u.t2<v.t2;} int main () {int n,m,i,j,k,b,c,d,e,t,s,sum;int t;scanf ("%d", &t), while (t--) {scanf ('%d ', &n); for (i=0;i<n;i+ +) {scanf ("%d%d:%d%d:%d", &a[i].num,&b,&c,&d,&e); a[i].t1=b*100+c;a[i].t2=d*100+e;} Sort (a,a+n,cmp); for (i=1,t=a[0].t2,s=a[0].num;i<n;i++) {if (a[i].t1<t&&a[i].t2>t) {s+=a[i].num;t= A[i].t2;} else if (a[i].t1<t&&a[i].t2==t) {s+=a[i].num;} else if (a[i].t1>=t&&a[i].num<=s) {t=a[i].t2;} else if (a[i].t1>=t&&a[i].num> s) {s+= (a[i].num-s); t=a[i].t2;}} printf ("%d\n", s); }return 0;}

Second time-out idea:
/* spents: 1000ms *///This method timed out! The idea is to ask for the most of the bench, so we have to figure out when we need the bench, so//I forget the time of the maximum and minimum value, then I then traverse to see which time period of the input has this time, and then//explain this time need to add so many stool number, There are a lot of time does not include this moment I also have to traverse, so spent a lot of time//and also have input data need to spend time, to time sequencing takes time, so so many operations caused the phenomenon of time-out,//after learning to look at the problem in disguise, If every moment of the bench is not good, we can suddenly ask for//a time period of time corresponding to the bench, all the corresponding assignment to them, and then enter the second time period of their respective stools, and then add up//and then the maximum value, to the maximum value when we will encounter problems, That is the time array from which the value of the start, to which//value end, we can not reuse the loop to traverse to find the maximum value it, so we need to skillfully use the conditional statement to wear it, the//maximum value out! Each time a more than one statement, and save a loop to find the maximum value of time, so it does not time out! #include <stdio.h> #include <string.h> #include <algorithm>using namespace std;struct node{int num; int t1;int T2;} A[10005];int S[2500];int CMP (node U,node v) {if (U.T2==V.T2) return U.t1<v.t1;return u.t2<v.t2;} int max (int a,int b) {return a>b?a:b;} int main () {int n,m,i,j,k,b,c,d,e,t,mx;scanf ("%d", &n), while (n--) {memset (s,0,sizeof (s)), scanf ("%d", &m); (i=0;i<m;i++) {scanf ("%d%d:%d%d:%d", &a[i].num,&b,&c,&d,&e); a[i].t1=b*60+c;a[i].t2=d*60+e;} Sort (a,a+m,cmp); for (i=a[0].t1,t=0,mx=0;i<=a[m-1].t2;i++) {for (j=0;j<m;j++) {if (I&GT;=A[J].T1&AMP;&AMP;I&LT;A[J].T2) S[t]+=a[j].num;else if (i<a[j].t1) break;} Mx=max (Mx,s[t]); t++;} printf ("%d\n", MX);} return 0;}

After the arduous process, finally AC (method very good, later to think about using):
Time: 967ms//The problem of this method is more wonderful, he needs to count the number of times required for each moment of the bench, the maximum value of its corresponding bench! In the beginning to the end of this time period, all need the bench, so those moments corresponding to the array will need to add the number of bench///second input, but also to calculate the start time and end time, and then start and end of the time in the corresponding array must be added//the number of required bench; Until M, this can work out both the stools needed for each moment and the maximum number of stools needed at any given moment. And can figure out the maximum number of stools! That's a great way to do it! #include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;int main () {int n,m,i,j , k,t_begin,t_end,a,b,c,d,e,t[2000],max;scanf ("%d", &n), while (n--) {memset (t,0,sizeof (t)); scanf ("%d", &m); for (i=0,max=0;i<m;i++)//through the method of direct nesting, with input values, with the calculation of the answer, but also reduce the M cycle! {scanf ("%d%d:%d%d:%d", &a,&b,&c,&d,&e); T_begin=b*60+c;t_end=d*60+e;for (j=t_begin;j<t_end , j + +)//This start time and end time interval is shorter, the number of cycles also decreases {t[j]+=a;max= (T[j]>max)? T[j]:max;}} printf ("%d\n", Max);} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4883 Tiankeng ' s restaurant

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.