hdu-4883- (Best Coder) TIANKENG’s restaurant

简介: hdu-4883- (Best Coder) TIANKENG’s restaurant



TIANKENG’s restaurant

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


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      

 




题目分析:开始自己写的代码一直wa不知道怎么回事,后来听大神讲了一下,好像明白了,就是说如果第一组客人走后这些个椅子可以已给下一波用也可以给下下一波用,

那么我这个代码就出问题了,我这个代码是比较下一个区间和上一个区间是否相交或覆盖。也就是这种情况: 第一波来了6人吃完走了,第二波5人来了,没吃完呢,第三波5人来了。如果是这个代码结果就是  11 了。但是事实上结果应该是 10的。想一想是不是。



<span style="font-size:24px;">#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct people
{
    char st[20];//来的时间
    char et[20];//走的时间
    int sum;
}arr[10010];
bool cmp(people a,people b)
{
    return strcmp(a.et,b.et)<0;
}
int main()
{
    int t,n,i;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(i=0;i<n;++i)
            scanf("%d %s %s",&arr[i].sum,arr[i].st,arr[i].et);//以前写过一道题(hdu-开门人和关门人),这个时间可以用字符串比较,因为是按照一定格式写的,所以以字符串输入没问题
        sort(arr,arr+n,cmp);
        int cnt=arr[0].sum;
        
        for(i=1;i<n;++i)
        {
            if(strcmp(arr[i-1].et,arr[i].st)>0)//如果有公共部分
            {
                cnt+=arr[i].sum;
            }
            else
            {
                cnt=arr[i].sum>cnt?arr[i].sum:cnt;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}</span>



看这个代码也是暴力模拟解法也没超时,不过我感觉已经很巧妙了

<span style="font-size:24px;">#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define maxn 25000
int time[maxn];
int main()
{
  int n;
  scanf("%d",&n);
  while(n--)
  {
    int num,h1,t1,h2,t2,T;
    scanf("%d",&T);
    memset(time,0,sizeof(time));
    while(T--)
    { 
        scanf("%d %d:%d %d:%d",&num,&h1,&t1,&h2,&t2);
        int hour1=h1*60+t1;
        int hour2=h2*60+t2;
        time[hour1]+=num;
        time[hour2]-=num;
    } 
    int i,sum=0;
    for(i=1;i<=1440;i++)
    { 
        time[i]+=time[i-1];//这里必须是当前数量加上上一个时间点的数量,不理解的话可以拿上面说的   6 5 5 这个数据模拟一遍
        sum=max(sum,time[i]);//这里sum 要始终存最大值,自己模拟一下我说的这组数据就很好理解了
    }
       
    printf("%d\n",sum);
  }
  return 0;
 }</span> 




















目录
相关文章
|
存储 安全 Swift
【Swift开发专栏】Swift的懒加载与延迟初始化
【4月更文挑战第30天】Swift中的懒加载和延迟初始化是性能优化的关键技术。懒加载(lazy)推迟了变量直到首次访问时的初始化,减少启动时间和内存消耗。延迟初始化则允许变量在首次访问前保持未初始化状态。这两种方法都能提升应用性能,减少不必要的资源加载,并提高代码组织性。但要注意线程安全、资源管理以及代码可读性。
386 0
|
Python
写给新手的 python 的教程(三)
写给新手的 python 的教程(三)
213 0
|
2天前
|
人工智能 运维 安全
|
4天前
|
SpringCloudAlibaba 负载均衡 Dubbo
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
本文对比分析了SpringCloudAlibaba框架下Feign与Dubbo的服务调用性能及差异。Feign基于HTTP协议,使用简单,适合轻量级微服务架构;Dubbo采用RPC通信,性能更优,支持丰富的服务治理功能。通过实际测试,Dubbo在调用性能、负载均衡和服务发现方面表现更出色。两者各有适用场景,可根据项目需求灵活选择。
384 124
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
|
7天前
|
人工智能 JavaScript 测试技术
Qwen3-Coder入门教程|10分钟搞定安装配置
Qwen3-Coder 挑战赛简介:无论你是编程小白还是办公达人,都能通过本教程快速上手 Qwen-Code CLI,利用 AI 轻松实现代码编写、文档处理等任务。内容涵盖 API 配置、CLI 安装及多种实用案例,助你提升效率,体验智能编码的乐趣。
682 107
|
1天前
|
算法 Python
【轴承故障诊断】一种用于轴承故障诊断的稀疏贝叶斯学习(SBL),两种群稀疏学习算法来提取故障脉冲,第一种仅利用故障脉冲的群稀疏性,第二种则利用故障脉冲的额外周期性行为(Matlab代码实现)
【轴承故障诊断】一种用于轴承故障诊断的稀疏贝叶斯学习(SBL),两种群稀疏学习算法来提取故障脉冲,第一种仅利用故障脉冲的群稀疏性,第二种则利用故障脉冲的额外周期性行为(Matlab代码实现)
221 152
|
3天前
|
Java 数据库 数据安全/隐私保护
Spring 微服务和多租户:处理多个客户端
本文介绍了如何在 Spring Boot 微服务架构中实现多租户。多租户允许单个应用实例为多个客户提供独立服务,尤其适用于 SaaS 应用。文章探讨了多租户的类型、优势与挑战,并详细说明了如何通过 Spring Boot 的灵活配置实现租户隔离、动态租户管理及数据源路由,同时确保数据安全与系统可扩展性。结合微服务的优势,开发者可以构建高效、可维护的多租户系统。
200 127