hdu 5240 Exam(贪心)
Exam
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1944 Accepted Submission(s): 948
DRD has n exams. They are all hard, but their difficulties are different. DRD will spend at least ri hours on the i-th course before its exam starts, or he will fail it. The i-th course's exam will take place ei hours later from now, and it will last for li hours. When DRD takes an exam, he must devote himself to this exam and cannot (p)review any courses. Note that DRD can review for discontinuous time.
So he wonder whether he can pass all of his courses.
No two exams will collide.
There are T cases following. In each case, the first line contains an positive integer n≤105, and n lines follow. In each of these lines, there are 3 integers ri,ei,li, where 0≤ri,ei,li≤109.
3
3 2 2
5 100 2
7 1000 2
3
3 10 2
5 100 2
7 1000 2
Case #2: YES
- #include <bits/stdc++.h>
- using namespace std;
- const int MAXN = 1e5 + ;
- struct Node {
- int r;
- int e;
- int l;
- } w[MAXN];
- bool cmp(Node a, Node b)
- {
- return a.e < b.e;
- }
- int main()
- {
- int t;
- int n;
- int i;
- int spa;
- int cas = ;
- scanf("%d", &t);
- while (t--) {
- scanf("%d", &n);
- for (i = ; i < n; ++i) {
- scanf("%d%d%d", &w[i].r, &w[i].e, &w[i].l);
- }
- sort(w, w + n, cmp);
- printf("Case #%d: ", ++cas);
- spa = w[].e;
- spa -= w[].r;
- if (spa < ) {
- printf("NO\n");
- continue;
- }
- for (i = ; i < n; ++i) {
- spa += w[i].e - (w[i - ].e + w[i - ].l);
- spa -= w[i].r;
- if (spa < ) {
- printf("NO\n");
- continue;
- }
- }
- printf("YES\n");
- }
- return ;
- }
hdu 5240 Exam(贪心)的更多相关文章
- HDU 5240 Exam
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest 2015ACM-ICPC上海大都会赛 签到题 #include< ...
- Hdu 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- hdu 2037简单贪心--活动安排问题
活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...
- HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...
- HDU 4310 Hero (贪心算法)
A - Hero Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- hdu 4268 multiset+贪心
Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...
- hdu 4864 Task (贪心 技巧)
题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...
- 2017多校第10场 HDU 6178 Monkeys 贪心,或者DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只 ...
随机推荐
- MySQL中一致性非锁定读
一致性非锁定读(consistent nonlocking read)是指InnoDB存储引擎通过多版本控制(multi versionning)的方式来读取当前执行时间数据库中行的数据,如果读取的行 ...
- InnoDB 与 MyISAM 区别
1.myisam可以对索引进行压缩,innodb不压缩 2.索引都用b-tree, innodb使用 b+tree,NDB Cluster使用 T-Tree. 3.myisam 表级锁, inno ...
- https-SSL请求
# coding:utf-8import requests# 禁用安全请求警告from requests.packages.urllib3.exceptions import InsecureRequ ...
- Cocos2d-x3.0游戏实例之《别救我》第八篇——TiledMap实现关卡编辑器
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/musicvs/article/details/25368273 好吧.我真心全然搞不懂.我如今仅仅只 ...
- Python学习笔记1_初识Python
一.Python的发展 1.CNRI时期:CNRI是自助Python发展初期的重要单位,Python1.5版之前的成果大部分都在此时期内完成 2.BeOpen时期:Guido van Rossum与B ...
- 实现对第三方应用任意SO注入
实现对第三方应用任意SO注入 0x01 应用在Android中运行,从外部对该进程可以进行任意SO文件动态注入,就是应用动态运行我们的SO文件 0x02 基本的逻辑是: 1. 获取目标进程的pi ...
- iOS 视图控制器转场动画/页面切换效果/跳转动画 学习
一 学习 在 UINavigationController 中 push 和 pop 的转场效果 (基于iOS7 以上的转场方式) 经过学习了解到,重点分三块: (1)pushAnimation: ...
- $Android自定义控件风格的方法
EditText在获取焦点后默认的边框都是黄色的,这可能和我在开发的应用的主题颜色不匹配,那怎么办呢?——用自定义的控件风格,比如说我想让EditText在获取焦点时候边框变成蓝色的,而失去焦点后边框 ...
- CentOS7,将文本模式改成图形界面模式
在以前通过vi /etc/inittab,将3修改成5.但是在centOS7之后将修改的办法换掉了,执行systemctl set-default graphical.target.根据提示进行一步一 ...
- Django组件 用户认证,form
auth模块 在进行用户登陆验证的时候,如果是自己写代码,就必须要先查询数据库,看用户输入的用户名是否存在于数据库中: 如果用户存在于数据库中,然后再验证用户输入的密码,这样一来就要自己编写大量的代码 ...