HDU 4883 (BC#2 1001题)TIANKENG’s restaurant(水)

题目地址:HDU 4883

唉。。最近得了一种惯性。。刚学了什么就碰到个类似的就想用刚学的算法。。。原来这题如此简单。。当时真是想多了。。。。

只要在需要变化的点上设置一个值,是增多少还是减多少。然后当遍历过来的时候加上或减去这个值就行了。。。

代码如下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include<algorithm>

using namespace std;
int a[11000], dp[11000];
int main()
{
    int t, n, i, a1, b1, a2, b2, l, r, x, min1;
    scanf("%d",&t);
    while(t--)
    {
        memset(a,0,sizeof(a));
        memset(dp,0,sizeof(dp));
        x=0;
        min1=-1;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%d%d:%d%d:%d",&x,&a1,&b1,&a2,&b2);
            l=a1*60+b1;
            r=a2*60+b2;
            a[l]+=x;
            a[r]-=x;
        }
        x=a[0];
        dp[0]=x;
        for(i=1;i<=1440;i++)
        {
            dp[i]=dp[i-1]+a[i];
        }
        for(i=0;i<=1440;i++)
        {
            if(min1<dp[i])
                min1=dp[i];
        }
        printf("%d\n",min1);
    }
    return 0;
}

HDU 4883 (BC#2 1001题)TIANKENG’s restaurant(水)

时间: 2025-01-09 02:47:34

HDU 4883 (BC#2 1001题)TIANKENG’s restaurant(水)的相关文章

HDU 4883 Best Coder Round 2 TIANKENG’s restaurant 题解

有一组数据是客人到来和离开的时间,问需要多少张桌椅才能满足所有客人都能有位置坐的要求. 有人居然一开始就想到暴力法,以为数据量少,其实本题数据量不少了, 暴力法需要O(n*n)的时间效率了,显然是会超时的,故此需要O(n) 或者O(lgn)的算法. 属于一道想透了就非常容易的,但是没想过就会非常困难的题目. 解法是: 把所有客人到来和离开的时间都排成序列,每次客人到来需要n张桌椅,那么就+上n,每次客人离开就会返还n张桌椅,那么就-去n,求这样的最大值. 具体算法代码就那么几行,处理IO的代码都

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

有一组数据是在客人到达和出发时间,问:多少把椅子的能力,以满足所有客人的需求,可以有一个地方坐下要求. 有些人甚至开始考虑暴力法,这些数据是少,其实这个问题很多数据, 暴力需求O(n*n)的时间效率,显然,将加班,因此,有必要O(n) 或O(nlgn)算法. 属于一道想透了就很easy的,可是没想过就会很困难的题目. 解法是: 把全部客人到来和离开的时间都排成序列.每次客人到来须要n张桌椅,那么就+上n,每次客人离开就会返还n张桌椅,那么就-去n,求这种最大值. 详细算法代码就那么几行,处理IO

HDU 4907 (杭电BC#3 1001)Task schedule(水)

题目地址:HDU 4907 水题...不多说..哈希后从后往前遍历一遍就行了. 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include<a

hdu 5364 (bc#50 1001) Distribution money

Distribution money Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 276    Accepted Submission(s): 163 Problem Description AFA want to distribution her money to somebody.She divide her money into

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 思维题

链接: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

HDU 4908 (杭电 BC #3 1002题)BestCoder Sequence(DP)

题目地址:HDU 4908 这个题是从m开始,分别往前DP和往后DP,如果比m大,就比前面+1,反之-1.这样的话,为0的点就可以与m这个数匹配成一个子串,然后左边和右边的相反数的也可以互相匹配成一个子串,然后互相的乘积最后再加上就行了.因为加入最终两边的互相匹配了,那就说明左右两边一定是偶数个,加上m就一定是奇数个,这奇数个的问题就不用担心了. 代码如下: #include <iostream> #include <stdio.h> #include <string.h&g

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