hdu 4883

简单题,当时竟然没有敲出来╮(╯▽╰)╭。。。

方法:每个时间点排序从小到大排序,之后扫一遍即可:是进的时间点就加人,反之出人。更新最大值即可。。。。囧。。。

#include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
struct times
{
    bool io;
    int num;
    int time;
};
bool my(times a,times b)
{
    if(a.time!=b.time)return a.time<b.time;
    return a.io<b.io;
}
int main()
{
    int T;
    cin>>T;
    int n;
    while(T--)
    {
        scanf("%d",&n);
        vector<times>v(2*n);
        int sum=0;
        int s11,s12,s21,s22;int x; int  max=0;
        for(int i=0;i<n;i++)
        {
          scanf("%d %d:%d %d:%d",&x,&s11,&s12,&s21,&s22);
          v[i+n].num=v[i].num=x;
          v[i+n].io=0;
          v[i].io=1;
          v[i].time=s11*60+s12;
          v[i+n].time=s21*60+s22;
        }
        sort(v.begin(),v.end(),my);
        for(int i=0;i<2*n;i++)
        {
            if(v[i].io==1)
             {
                 sum+=v[i].num;
                 if(sum>max)max=sum;
             }
            else
              sum-=v[i].num;
        }
      printf("%d\n",max);
    }
    return 0;
}

hdu 4883

时间: 2024-10-07 23:06:01

hdu 4883的相关文章

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 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>

HDU 4883 TIANKENG’s restaurant (区间更新)

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

hdu 4883 区间选点

昨天比赛的时候没有做出来,本来是想用贪心的,但是贪了好久都没有招, 今天在网上搜了解题报告~好像说这是一类区间选点问题: 有一个好的做法: (1)首先把题目中的时间全转化为分钟,那么区间就在0-1440中间 (2)对于n组人,有一个si 和一个ei,那么开个数组, cnt[si]+=d;  cnt[ei]-=d; ( 3 ) 也就是说在数轴上讲到达的这点加上d,离开的这点减去d; 附上代码 #include <iostream> #include <cstdio> #include

HDU 4883 TIANKENG’s restaurant

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

hdu 4883 思维题

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 566    Accepted Submission(s): 267 Problem Description TIANKENG manages a