称号:

TIANKENG’s restaurant

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)

Total Submission(s): 249    Accepted Submission(s): 125

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
 

解题思路:

转换为RMQ问题,1天24h,1440min;a[i]表示第i分钟的人数,n表示时间[t1,t2)之间来的人数,对这个区间内的a[i]+n,最后求的是a[i]的最大值。

解法1:模拟

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define clr(a) memset(a, 0, sizeof(a))
#define rep(i,s,t) for(int i = s; i <= t; ++i)
#define per(i,s,t) for(int i = s; i >= t; --i) const int MAXN = 1450;
int t, n, a[MAXN]; int main()
{
scanf("%d", &t);
while(t--)
{
clr(a);
scanf("%d", &n);
int num, h1, m1, h2, m2;
rep(i,0,n-1)
{
scanf("%d%d:%d%d:%d", &num, &h1, &m1, &h2, &m2);
int s1 = h1 * 60 + m1, s2 = h2 * 60 + m2;
rep(j,s1,s2-1) a[j] += num;
}
int ans = -1;
rep(i,0,MAXN-1) ans = max(ans,a[i]);
printf("%d\n", ans);
}
return 0;
}

解法2:线段树(ZKW)

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define clr(a) memset(a, 0, sizeof(a))
#define rep(i,s,t) for(int i = s; i <= t; ++i)
#define per(i,s,t) for(int i = s, i >= t; --i) const int M = 1<<11, MAXN = 1440;
int icase, n, a[M << 1]; void Add_x(int s, int t, int x)
{
int b = 0;
for(s=s+M-1, t=t+M+1; s^t^1; s>>=1, t>>=1)
{
if(~s&1) a[s^1] += x;
if( t&1) a[t^1] += x;
b = max(a[s], a[s^1]), a[s]-=b, a[s^1]-=b, a[s>>1]+=b;
b = max(a[t], a[t^1]), a[t]-=b, a[t^1]-=b, a[t>>1]+=b;
// printf("%d %d %d %d\n", s, t, a[s^1], a[t^1]);
}
for( ; s > 1; s>>=1)
b = max(a[s], a[s^1]), a[s]-=b, a[s^1]-=b, a[s>>1]+=b;
} int Max(int s, int t)
{
int lans = 0, rans = 0, ans = 0;
for(s=s+M-1,t=t+M+1; s^t^1; s>>=1, t>>=1)
{
lans+=a[s], rans+=a[t];
if(~s&1) lans = max(lans, a[s^1]);
if( t&1) rans = max(rans, a[t^1]);
// printf("%d %d %d %d\n", s, t, lans, rans);
}
ans = max(lans+a[s], rans+a[t]);
while(s>1) ans+=a[s>>=1];
return ans;
} void show()
{
for(int i = 0; i < M; i++)
printf("%d ", a[i]);
printf("\n");
} int main()
{
scanf("%d", &icase);
while(icase--)
{
scanf("%d", &n); clr(a);
int num, h1, m1, h2, m2;
for(int i = 0; i < n; ++i)
{
scanf("%d%d:%d%d:%d", &num, &h1, &m1, &h2, &m2);
int s1 = h1 * 60 + m1, s2 = h2 * 60 + m2;
Add_x(1+s1, s2, num);
}
// show();
printf("%d\n", Max(1,1440));
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

HDOJ 4883 TIANKENG’s restaurant的更多相关文章

  1. hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】

    TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/O ...

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

    TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/O ...

  3. 杭电 4883 TIANKENG’s restaurant (求饭店最少需要座椅)

    Description TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of custo ...

  4. HDU 4883 TIANKENG’s restaurant

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 解题报告:一家餐馆一天中有n波客人来吃饭,第 i 波  k 客人到达的时间是 s ,离开时的时间 ...

  5. HDU 4883 TIANKENG’s restaurant (贪心)

    链接:pid=4883">带我学习.带我飞 第一次BC,稳挂,WA n多次.今天又一次做了一下 略挫 #include <iostream> #include <cs ...

  6. hdu4886 TIANKENG’s restaurant(Ⅱ) (trie树或者模拟进制)

    TIANKENG’s restaurant(Ⅱ) Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 130107/65536 K (Ja ...

  7. HDU 4886 TIANKENG’s restaurant(Ⅱ) ( 暴力+hash )

    TIANKENG’s restaurant(Ⅱ) Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 130107/65536 K (Ja ...

  8. TIANKENG’s restaurant HDU - 4883 (暴力)

    TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to ...

  9. HDU 4883 Best Coder Round 2 TIANKENG’s restaurant 解读

    有一组数据是在客人到达和出发时间,问:多少把椅子的能力,以满足所有客人的需求,可以有一个地方坐下要求. 有些人甚至开始考虑暴力法,这些数据是少,其实这个问题很多数据, 暴力需求O(n*n)的时间效率, ...

随机推荐

  1. 无线网络wifi (WPA/WPA2)密码破解方法

    无线网络password破解WPA/WPA2教程 本教程用于探索无线路由安全漏洞,禁止用于非法用途,违者法律必究(与我无关) 在动手破解WPA/WPA2前,应该先了解一下基础知识,本文适合新手阅读 首 ...

  2. 修改、设置root密码

    参考文档: http://zhidao.baidu.com/link?url=OaUTAj6FrMGDjbPZHWv3NNDOaIl3HNqZz_3lF_Zpi8oZpLkBfnHfPlpgE1EvN ...

  3. Effective C++ Item 40 明智而审慎地使用多重继承

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:多重继承比单一继承复杂.它可能导致新的歧义性,以及对 virtual 继承的须要 演示 ...

  4. C#数组集合使用 排序的问题

    //没有顺序 //ArrayList a = new ArrayList(); //a.Add("asda"); //a.Add("asda222222"); ...

  5. webform之session传值(临时数据的存储)与扩展属性 --(购物车练习)

    页面传值:1.QueryString传值在源页面写:Response.Redirect("Main.aspx?uid="+uid+"&pwd="+pwd ...

  6. 算法之旅,直奔<algorithm>之十 count_if

    count_if(vs2010) 引言 这是我学习总结<algorithm>的第十篇,这个重要的地方是设置条件.用的还是蛮多的.(今天下午挺恶心的,一下午就做一个面试题,调代码调傻了... ...

  7. WPF4多点触摸事件

    原文 WPF4多点触摸事件 UIElement在WPF4下添加了很多支持多点触摸的事件,通过它们可以在硬件支持的情况下处理多点触摸,以下通过代码来说明通过处理这些事件,我们可以做些什么: 一.触摸相关 ...

  8. lokijs

    http://lokijs.org/#/ 500,000+ 1.1M ops/s. A fast, in-memory document-oriented datastore for node.js, ...

  9. 清华集训2014 day1 task1 玛里苟斯

    题目 这可算是描述很简单的一道题了!但是不简单. \(S\)是一个可重集合,\(S = \{a_1, a_2, \dots, a_n \}\). 等概率随机取\(S\)的一个子集\(A = \{a_{ ...

  10. PHP - 子类使用父类的构造函数

    /* * 子类使用父类中的构造方法. */ //父类方法 class Person { //父类中的构造方法 function __construct(){ echo '这是父类中的构造方法!'; } ...