D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心)
James is almost mad! Currently, he was assigned a lot of works to do,
so many that you can't imagine. Each task costs Ai time as least, and
the worst news is, he must do this work no later than time Bi!OMG, how could it be conceivable! After simple estimation, he
discovers a fact that if a work is finished after Bi, says Ti, he will
get a penalty Ti - Bi. Though it may be impossible for him to finish
every task before its deadline, he wants the maximum penalty of all
the tasks to be as small as possible. He can finish those tasks at any
order, and once a task begins, it can't be interrupted. All tasks
should begin at integral times, and time begins from 0. Input The
first line contains a single integer T, indicating the number of test
cases. Each test case includes an integer N. Then N lines following,
each line contains two integers Ai and Bi.Technical Specification
- 1 <= T <= 100
- 1 <= N <= 100 000
- 1 <= Ai, Bi <= 1 000 000 000 Output For each test case, output the case number first, then the smallest maximum penalty.
Sample Input
2
2
3 4
2 2
4
3 6
2 7
4 5
3 9
Sample Output
Case 1: 1
Case 2: 3
思路
- 贪心 + 结构排序
代码
#include<iostream>
#include<cmath>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int Len = 100005;
struct Node
{
ll s, e;
bool operator < (const Node b) const
{
if(e == b.e)
return s < b.s;
return e < b.e;
}
} node[Len];
int main()
{
/* freopen("A.txt","r",stdin); */
int t, Case = 1;
scanf("%d", &t);
while(t --)
{
ll n;
scanf("%lld", &n);
for(int i = 1; i <= n; i ++)
scanf("%lld %lld", &node[i].s, &node[i].e);
sort(node + 1, node + 1 + n);
ll ans = 0;
ll sum = 0;
for(int i = 1; i <= n; i ++)
{
sum += node[i].s;
if(sum > node[i].e)
ans = max(ans, sum - node[i].e);
}
printf("Case %d: %lld\n", Case ++, ans);
}
return 0;
}
D - 淡黄的长裙 HDU - 4221(贪心)的更多相关文章
- HDU - 4221 贪心
题意: 你有n个任务,每一个任务有一个完成所需时间AI,和一个截止时间BI.时间从0开始,如果完成任务的时间(设这个时间为ans)大于BI那么就会收到ans-BI的惩罚,问你完成所有这些任务你会收到的 ...
- Hdu 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- hdu 1735(贪心) 统计字数
戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...
- hdu 4974 贪心
http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...
- hdu 4982 贪心构造序列
http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...
- HDU 2307 贪心之活动安排问题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1052 贪心+dp
http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS ...
- HDU 2111 Saving HDU【贪心】
解题思路:排序后贪心,和fatmouse's trade 类似 Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: ...
随机推荐
- 趣谈编程史第3期-大器晚成的新晋流量Python发展史
写在前面 这篇博文主要介绍javaScript的发展史,根据作者在B站发布的同名视频的文案整理修改而成,对视频感兴趣的博友可访问https://www.bilibili.com/video/av860 ...
- vue如何新建一个项目
第一步:安装node 首先下载安装node 安装步骤参考:https://www.cnblogs.com/qdwz/p/10820554.html window+R打开控制命令行cmd node -v ...
- RabbitMQ面试题集锦(精选)(另附思维导图)
1.使用RabbitMQ有什么好处? 1.解耦,系统A在代码中直接调用系统B和系统C的代码,如果将来D系统接入,系统A还需要修改代码,过于麻烦! 2.异步,将消息写入消息队列,非必要的业务逻辑以异步的 ...
- 无刷新上传图片,ajax 和 iframe
iframe 上传 upload.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...
- django学习笔记 多文件上传
习惯了flask 再用django 还是不太习惯 好麻烦 配置文件也忒多了 不过还是要学的 之前只能一个一个文件长传,这次试试多个文件 不适用django的forms创建表单 直接在html中使用 ...
- linux ftp服务器设置,只允许用户访问指定的文件夹,禁止访问其他文件夹
在Linux中添加ftp用户,并设置相应的权限,操作步骤如下: 1.环境:ftp为vsftp.被限制用户名为test.被限制路径为/home/test 2.建用户:在root用户下: useradd ...
- 5G 将带给程序员哪些新机会呢?
5G,第 5 代移动通信技术,华为在此领域远远领先同行,这也让它成了中美贸易战的最前线.我的第一份工作就在通信行业,当时电信标准都在欧美企业手里,国内企业主要是遵照标准研发软硬件设备,核心芯片靠进口. ...
- 微信小程序接入LeanCloud
大家在做小程序或者客户端开发的时候肯定会想使得数据进行联网,但这样就必须有对应的后台服务器以及数据库,再加上linux运维等各种细节,往往会对新手比较劝退,在这里给大家推荐一种bass(后端即服务), ...
- iview Checkbox 多选框 单个的时候 如果需要change 以后进行赋值 就要用value 不要用v-modal 然后用updateModel 方法
noSuchSituationSetFalse () { this.noSuchSituationOne = false this.$refs.noSuchSituationRef.updateMod ...
- 编译Zookeeper3.4.6源代码并通过Intellij IDEA运行(2020年)
一.问题背景 生产环境Windows机器上用的Zookeeper 3.4.6,最近经常报如下异常: 经过搜索,看到一篇帖子可以解决:https://www.jianshu.com/p/73eec030 ...