HDU Hangzhou Electric 4883 Tiankeng ' s Restaurant

Source: Internet
Author: User
Tags strcmp

Problem Descriptiontiankeng manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to ha ve 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, output the minimum number of chair that 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

I wrote the code in the game, again wrong, thinking I feel no fault, know the great God help me correct

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;struct people{    Char st[20];//come time    Char et[20];//walk time    int sum;} Arr[10010];bool cmp (People a,people b) {    return strcmp (A.et,b.et) <0;} int main () {    int t,n,i;    scanf ("%d", &t);    while (t--)    {        scanf ("%d", &n);        for (i=0;i<n;++i)            scanf ("%d%s%s", &arr[i].sum,arr[i].st,arr[i].et);//Previously written a question, this time can be compared by a string, Because it is written in a certain format, the string input is no problem        sort (arr,arr+n,cmp);        int cnt=arr[0].sum;                for (i=1;i<n;++i)        {if            (strcmp (arr[i-1].et,arr[i].st) >0)//If there is a public part            {                cnt+=arr[i].sum;            }            else            {                cnt=arr[i].sum>cnt?arr[i].sum:cnt;            }        }        printf ("%d\n", CNT);    }    return 0;}


AC Code

/* Test instructions: Greet guests at different times with minimum number of seats */#include <cstdio> #include <cstring> #include <algorithm>using Namespace Std;int a[1000010];int Main () {int t,n,s;int i,j;int max;int hour1,hour2,min1,min2; scanf ("%d", &t); while ( t--) {memset (a,0,sizeof (a));//start with 0 scanf ("%d", &n), max=-100;//record the smallest seat for (I=0;i<n;++i) {scanf ("%d%d:%d%d:% D ", &s,&hour1,&min1,&hour2,&min2);//s represents the number of people in this time period int sum1=hour1*60+min1;// Each time has a sum1 and sum2 this interval int sum2=hour2*60+min2;for (J=SUM1;J<SUM2;++J)//When two intervals have a public part, the array a[i] just saved a number {a[j]+=s;if (a[ J]>max)//When the number of seats in the array a record is greater than Max, update Max MAX=A[J];}} printf ("%d\n", Max);} return 0;}


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

HDU Hangzhou Electric 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.