zoukankan      html  css  js  c++  java
  • hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】

    TIANKENG’s restaurant

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


    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
    题并不难,
    题意:一组数据中每个开头是一个整数代表此组人的人数,接下来是此组人的到达时间和走的时间,如果两组人的
            时间区间不相交,则第二组人可以使用第一组人用过的桌子,如果相交,就必须重新安排桌子,问最少需要多少桌子
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #define MAX 10010
    using namespace std;
    struct node
    {
    	int come;
    	int go;
    	int peo;
    }s[MAX];
    int dp[MAX];
    bool cmp(int a,int b)
    {
    	return a>b;
    }
    int main()
    {
    	int t,n,m,j,i;
    	int ha,hb,ma,mb;
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d",&n);
    		memset(dp,0,sizeof(dp));
    		for(i=0;i<n;i++)
    		{
    			scanf("%d %d:%d %d:%d",&s[i].peo,&ha,&ma,&hb,&mb);
    		    s[i].come=ha*60+ma;
    		    s[i].go=hb*60+mb;
    		    for(j=s[i].come;j<s[i].go;j++)
    		    {
    		    	dp[j]+=s[i].peo;
    		    }
    		}
    		sort(dp,dp+MAX,cmp);
    		printf("%d
    ",dp[0]);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    【总结】数组去重的3种方式
    【原】运动版的轮播图,有左右按钮和单独分页,原生JS版
    【巩固】JS中的封闭空间
    IIS 配置.svc的MIME映射
    c# 线程定时器 System.Threading.Timer 转载
    QTcreator快捷操作,转载
    C#中的钩子说明
    anaconda更新库命令
    Chart控件,chart、Series、ChartArea曲线图绘制的重要属性介绍
    c# chart控件柱状图,改变柱子宽度
  • 原文地址:https://www.cnblogs.com/tonghao/p/4691170.html
Copyright © 2011-2022 走看看