HDU4883TIANKENG’s restaurant

题目:HDU4883TIANKENG’s restaurant

题目大意:一间餐厅,给你每组客人的人数和来的时间,离开的时间,问最少需要的椅子。

解题思路:这题本来想用区间覆盖做,可是后面发觉不太对。这题貌似暴力也是可以过的,因为时间才1440.其中的一种做法:把每个区间的开始和结束时间点都标记上是来人还是走人,对应的椅子数加上减去。然后在枚举一下时间,在这个过程中维护椅子的最大值。也可以把出入的时间点记录下来,因为这些时间点人数是在变化的,然后也是维护最大值,但是要记得重复的时间点不要加多次。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 2005;
int c[N];

int main () {

	int T;
	int num, h, m;
	int ans, n;
	scanf ("%d", &T);
	while (T--) {

		scanf ("%d", &n);
		memset (c, 0, sizeof (c));
		for (int i = 0; i < n; i++) {
			scanf ("%d", &num);

			scanf ("%d:%d", &h, &m);
			c[h * 60 + m] += num;

			scanf ("%d:%d", &h, &m);
			c[h * 60 + m] -= num;
		}

		int ans = 0;
		int tmp = 0;
		for (int i = 0; i < N; i++) {
			tmp += c[i];
			if (tmp > ans)
				ans = tmp;
		}
		printf ("%d\n", ans);
	}
	return 0;
}
时间: 2024-10-11 21:07:00

HDU4883TIANKENG’s restaurant的相关文章

URAL1962:In Chinese Restaurant(并查集)

When Vova arrived in Guangzhou, his Chinese friends immediately invited him to a restaurant. Overalln people came to the restaurant, including Vova. The waiter offered to seat the whole company at a traditional large round table with a rotating dish

BestCoder Round #2 1001 TIANKENG’s restaurant

不得不说,bastcoder是个hack游戏啊!!! 题意:求最少要多少张椅子才能让所有来的客人有地方坐!! 就是一个区间的处理吧!!!和HDU  1556 我待水似流年,流年待我似水神似!!!! 求的是重叠的区间最大,我们只要标记每个区间会有多少人就可以了!!! 然后在从0到1440分统计就OK了!! AC代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<map> #inc

hdu 4883 TIANKENG’s restaurant(暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 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 t

HDU 4883 TIANKENG’s restaurant Bestcoder 2-1(模拟)

TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description TIANKENG manages a restaurant after graduating from ZCMU, and tens of t

HDU 4883 TIANKENG’s restaurant(区间选点)

HDU 4883 TIANKENG's restaurant 题目链接 题意:给定一些时间作为区间,和一个人数,问要安排多少人去看管(一个人只能看管一个人) 思路:普通的区间选点问题,一个区间拆成一个进入点一个出去点,然后排序循环求答案即可 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 20005; struct Man {

HDU ACM 1103 Flo&#39;s Restaurant

分析:借助STL的min_element实现.每次更新最先被占用的桌子,具体见注释. #include<iostream> #include<algorithm> using namespace std; int main() { int A,B,C; char s[10]; int a[102],b[102],c[102]; int curtime,count,ans; int *p; //桌子最先空闲时间 while(cin>>A>>B>>C

ZOJ 3317 Murder in Restaurant(数学啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3317 Murder in closet happened again in a small restaurant and Conan went there to collect evidence with Kogoro. After they reached the restaurant, they got a list of renters that live

HDU 4883 Best Coder Round 2 TIANKENG’s restaurant 题解

有一组数据是客人到来和离开的时间,问需要多少张桌椅才能满足所有客人都能有位置坐的要求. 有人居然一开始就想到暴力法,以为数据量少,其实本题数据量不少了, 暴力法需要O(n*n)的时间效率了,显然是会超时的,故此需要O(n) 或者O(lgn)的算法. 属于一道想透了就非常容易的,但是没想过就会非常困难的题目. 解法是: 把所有客人到来和离开的时间都排成序列,每次客人到来需要n张桌椅,那么就+上n,每次客人离开就会返还n张桌椅,那么就-去n,求这样的最大值. 具体算法代码就那么几行,处理IO的代码都

HDU 4883 TIANKENG’s restaurant (贪心)

链接:带我学习,带我飞 第一次BC,稳挂,WA n多次,今天重新做了一下 略挫 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include <string> #include <vector> #include <set> #include <algorithm>