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)推迟了变量直到首次访问时的初始化,减少启动时间和内存消耗。延迟初始化则允许变量在首次访问前保持未初始化状态。这两种方法都能提升应用性能,减少不必要的资源加载,并提高代码组织性。但要注意线程安全、资源管理以及代码可读性。
401 0
|
Python
写给新手的 python 的教程(三)
写给新手的 python 的教程(三)
215 0
|
3天前
|
存储 关系型数据库 分布式数据库
PostgreSQL 18 发布,快来 PolarDB 尝鲜!
PostgreSQL 18 发布,PolarDB for PostgreSQL 全面兼容。新版本支持异步I/O、UUIDv7、虚拟生成列、逻辑复制增强及OAuth认证,显著提升性能与安全。PolarDB-PG 18 支持存算分离架构,融合海量弹性存储与极致计算性能,搭配丰富插件生态,为企业提供高效、稳定、灵活的云数据库解决方案,助力企业数字化转型如虎添翼!
|
14天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1305 5
|
13天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
1332 87
|
2天前
|
弹性计算 安全 数据安全/隐私保护
2025年阿里云域名备案流程(新手图文详细流程)
本文图文详解阿里云账号注册、服务器租赁、域名购买及备案全流程,涵盖企业实名认证、信息模板创建、域名备案提交与管局审核等关键步骤,助您快速完成网站上线前的准备工作。
184 82
2025年阿里云域名备案流程(新手图文详细流程)