HDU 4883 tiankeng's restaurant (Interval Update)

Source: Internet
Author: User
Problem descriptiontiankeng manages a restaurant after graduating from zcmu, and tens of thousands of MERs come to have meal because of its delicious dishes. today N groups of MERs 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. cocould you Help tiankeng calculate the minimum chairs he needs to prepare so that every customer can take a seat when arriving 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 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.
 


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:5926 08:00 09:005 09:00 10:00
 


Sample output
116


This question is easy to think of using the line segment tree to update, and the line segment tree is used during the competition, but in fact, using the line segment tree to update is a little useful, because the question only needs to be queried once, there is no dynamic update or query.

You can use a sum array to record the total number of users in the point. During input, you can pre-process the changes of the first batch of guests. When sum [I] is used, the corresponding number of people is added. When sum [I] is used, the corresponding number is subtracted.

The formula sum [I] + = sum [I-1]; I indicates the passage of time, which can be pushed from 0th minutes to the end time. Because there is no need to update again or query during this period, this algorithm is more advantageous than the line segment tree.


#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>#include <stack>#define lson o<<1, l, m#define rson o<<1|1, m+1, rusing namespace std;typedef long long LL;const int maxn = 1500;const int MAX = 0x3f3f3f3f;const int mod = 1000000007;int t, n;int sum[maxn];int main(){    scanf("%d", &t);    while(t--) {        scanf("%d", &n);        memset(sum, 0, sizeof(sum));        for(int i = 0; i < n; i++) {            int tmp, h1, m1, h2, m2;            scanf("%d %d:%d %d:%d", &tmp, &h1, &m1, &h2, &m2);            int st = h1*60+m1;            int en = h2*60+m2;            sum[st] += tmp;            sum[en] -= tmp;        }        int ans = sum[0];        for(int i = 1; i <= 1440; i++) {            sum[i] += sum[i-1];            ans = max(ans, sum[i]);        }        printf("%d\n", ans);    }    return 0;}



Zookeeper

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.