码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4883--TIANKENG’s restaurant【区间覆盖 && 暴力】

时间:2015-08-01 01:05:44      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

TIANKENG’s restaurant

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


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 

一开始以为以为是贪心, 直接wa了 ,后来好好读都体,发现时区间覆盖的问题,但是数据小,暴力应该可以过,就试了一下裸暴力,超时,后来又把暴力优化了一下才过。


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int str[4000];
int main (){
	int T;
	scanf("%d", &T);
	while(T--){
		int m;
		scanf("%d", &m);
		int n, h1, m1, h2, m2, sum;
		memset(str, 0, sizeof(str));
		sum = 0;
		while(m--){
			scanf("%d%d:%d%d:%d", &n, &h1, &m1, &h2, &m2);
			int time1 = h1 * 60 + m1;
			int time2 = h2 * 60 + m2;
			str[time1] += n;
			str[time2] -= n;
		}
		for(int i = 1; i <= 1440; ++i){
			str[i] += str[i - 1];
			sum = max(sum, str[i]);
		}
		printf("%d\n", sum); 
	}
	return 0;
} 


超时代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int main (){
    int T;
    scanf("%d", &T);
    int str[11000];
    while(T--){
        int m;
        scanf("%d", &m);
        int n, h1, m1, h2, m2, sum;
        memset(str, 0, sizeof(str));
        sum = 0;
        while(m--){
            scanf("%d%d:%d%d:%d", &n, &h1, &m1, &h2, &m2);
            int time1 = h1 * 60 + m1;
            int time2 = h2 * 60 + m2;
            for(int i = time1; i < time2; ++i){
                str[i] += n;
                sum = max(str[i], sum);
            }
        }
        printf("%d\n", sum);
    }
    return 0;
} 



版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 4883--TIANKENG’s restaurant【区间覆盖 && 暴力】

标签:

原文地址:http://blog.csdn.net/hpuhjh/article/details/47178663

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!