HDU4883 TIANKENG’s restaurant 【贪心】

TIANKENG’s restaurant

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


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 maxn 1500
using std::max_element;

int arr[maxn];

int main()
{
    int t, n, i, h, m, h2, m2, people, j;
    scanf("%d", &t);
    while(t--){
        memset(arr, 0, sizeof(arr));
        scanf("%d", &n);
        for(i = 0; i < n; ++i){
            scanf("%d %d:%d %d:%d", &people, &h, &m, &h2, &m2);
            m += h * 60; m2 += h2 * 60;
            for(j = m; j < m2; ++j) arr[j] += people;
        }
        printf("%d\n", *max_element(arr, arr + 1500));
    }
    return 0;
}

写了个线段树版本的,RE,但不知错哪了。

#include <stdio.h>
#include <string.h>
#define maxn 1502
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1

int tree[maxn << 2], lazy[maxn << 2];

int max(int a, int b)
{
    return a > b ? a : b;
}

void pushDown(int l, int r, int rt)
{
    lazy[rt << 1] += lazy[rt];
    lazy[rt << 1 | 1] += lazy[rt];
    tree[rt << 1] += lazy[rt];
    tree[rt << 1 | 1] += lazy[rt];
    lazy[rt] = 0;
}

void pushUp(int l, int r, int rt)
{
    tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);
}

void build(int l, int r, int rt)
{
    tree[rt] = lazy[rt] = 0;
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(lson);
    build(rson);
}

void update(int left, int right, int val, int l, int r, int rt)
{
    if(left == l && right == r){
        lazy[rt] += val; 
        tree[rt] += val; 
        return;
    }
    if(lazy[rt]) pushDown(l, r, rt);
    int mid = (l + r) >> 1;
    if(right <= mid) update(left, right, val, lson);
    else if(left > mid) update(left, right, val, rson);
    else{
        update(left, mid, val, lson);
        update(mid + 1, right, val, rson);
    }
    pushUp(l, r, rt);
}

int main()
{
    //freopen("stdin.txt", "r", stdin);
    int t, n, i, h0, m0, h1, m1, val;
    scanf("%d", &t);
    while(t--){
        build(0, 1500, 1);
        scanf("%d", &n);
        for(i = 0; i < n; ++i){
            scanf("%d %d:%d %d:%d", &val, &h0, &m0, &h1, &m1);
            m0 += h0 * 60; m1 += h1 * 60; --m1;
            update(m0, m1, val, 0, 1500, 1);
        }
        printf("%d\n", tree[1]);
    }
    return 0;
}


内容概要:本文介绍了多种开发者工具及其对开发效率的提升作用。首先,介绍了两款集成开发环境(IDE):IntelliJ IDEA 以其智能代码补全、强大的调试工具和项目管理功能适用于Java开发者;VS Code 则凭借轻量级和多种编程语言的插件支持成为前端开发者的常用工具。其次,提到了基于 GPT-4 的智能代码生成工具 Cursor,它通过对话式编程显著提高了开发效率。接着,阐述了版本控制系统 Git 的重要性,包括记录代码修改、分支管理和协作功能。然后,介绍了 Postman 作为 API 全生命周期管理工具,可创建、测试和文档化 API,缩短前后端联调时间。再者,提到 SonarQube 这款代码质量管理工具,能自动扫描代码并检测潜在的质量问题。还介绍了 Docker 容器化工具,通过定义应用的运行环境和依赖,确保环境一致性。最后,提及了线上诊断工具 Arthas 和性能调优工具 JProfiler,分别用于生产环境排障和性能优化。 适合人群:所有希望提高开发效率的程序员,尤其是有一定开发经验的软件工程师和技术团队。 使用场景及目标:①选择合适的 IDE 提升编码速度和代码质量;②利用 AI 编程助手加快开发进程;③通过 Git 实现高效的版本控制和团队协作;④使用 Postman 管理 API 的全生命周期;⑤借助 SonarQube 提高代码质量;⑥采用 Docker 实现环境一致性;⑦运用 Arthas 和 JProfiler 进行线上诊断和性能调优。 阅读建议:根据个人或团队的需求选择适合的工具,深入理解每种工具的功能特点,并在实际开发中不断实践和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值