程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> [ACM] HDU 4883 TIANKENG’s restaurant

[ACM] HDU 4883 TIANKENG’s restaurant

編輯:C++入門知識

[ACM] HDU 4883 TIANKENG’s restaurant


TIANKENG’s restaurant

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 931 Accepted Submission(s): 412


Problem Description

TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to have meal because of its delicious dishes. Today n groups of customers come to enjoy their meal, and there are Xi persons in the ith group in sum. Assuming that each customer can own only one chair. Now we know the arriving time STi and departure time EDi of each group. Could you help TIANKENG calculate the minimum chairs he needs to prepare so that every customer can take a seat when arriving the restaurant?


Input

The 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 is 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<60), Given that the arriving time must be earlier than the departure time.

Pay attention that when a group of people arrive at the restaurant as soon as a group of people leaves from the restaurant, then the arriving group can be arranged to take their seats if the seats are enough.


Output

For each test case, output the minimum number of chair that TIANKENG needs to prepare.


Sample Input

2
2
6 08:00 09:00
5 08:59 09:59
2
6 08:00 09:00
5 09:00 10:00


Sample Output

11
6


Source

BestCoder Round #2

解題思路:

題意為:有n組客人來吃飯,給出每組客人的人數及用餐開始時間,結束時間,格式為hh:mm;要求一組客人來的時候就必須給其安排位子
,問最少需要多少把椅子才能做到(一位客人需要一把椅子).

time[i],表示第i分鐘有多少用餐的人,也就是需要多少把椅子,將開始時間,結束時間轉化為分鐘為單位的時間。
注意邊界一組的結束和另一組的開始如果相同,則不需要額外的椅子,因此把每組的結束時間都-1. 對於每一組人,開始時間到結束時間
循環time[i]+=該組的人數。 最後再遍歷time[i]數組,從中找到最大值即為該題的答案。

代碼:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define ll long long
int n;
int time[1442];

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(time,0,sizeof(time));
        scanf("%d",&n);
        int sh,sm;
        int eh,em;
        int cnt=0;
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&cnt);
            scanf("%d:%d",&sh,&sm);
            scanf("%d:%d",&eh,&em);
            int s=sh*60+sm;
            int e=eh*60+em;
            e--;
            for(int i=s;i<=e;i++)
            {
                time[i]+=cnt;
            }
        }
        for(int i=0;i<1440;i++)
        {
            if(ans


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved