Exam

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1944    Accepted Submission(s): 948

Problem Description
As this term is going to end, DRD needs to prepare for his final exams.

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. 

 
Input
First line: an positive integer T≤20 indicating the number of test cases.
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.

 
Output
For each test case: output ''Case #x: ans'' (without quotes), where x is the number of test cases, and ans is ''YES'' (without quotes) if DRD can pass all the courses, and otherwise ''NO'' (without quotes).

 
Sample Input
2
3
3 2 2
5 100 2
7 1000 2
3
3 10 2
5 100 2
7 1000 2
 
Sample Output
Case #1: NO
Case #2: YES
 
Source
 
 
 #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(贪心)的更多相关文章

  1. HDU 5240 Exam

    The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest 2015ACM-ICPC上海大都会赛 签到题 #include< ...

  2. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  3. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  4. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  5. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  6. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  7. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

  8. hdu 4864 Task (贪心 技巧)

    题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...

  9. 2017多校第10场 HDU 6178 Monkeys 贪心,或者DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只 ...

随机推荐

  1. Vue.js中css的作用域

    Vue.js中的css的作用域问题: 如果在vue组件下的style中定义样式,效果会作用于整个html页面,如果只想本组件的css样式只作用于本组件的话,在<style>标签里添加sco ...

  2. 003-诠释 Java 工程师【一】

    一.基础篇 1.面向对象的三大特性 继承.封装.多态 什么是继承? ①继承是面向对象程序设计能够提高软件开发效率的重要原因之一. ②继承是具有传递性的,就像现实中孙子不仅长得像爸爸而且还像他爷爷. ③ ...

  3. MySQL中kill所有慢查询进程和锁表进程

    1.kill所有慢查询进程: #!/bin/bash mysql -uroot -pMy_Password -e "show processlist" | grep -i &quo ...

  4. ASP.NET,什么是MVC,MVC的简单介绍

    什么是MVC模式 MVC(Model-View-Controller,模型—视图—控制器模式)用于表示一种软件架构模式.它把软件系统分为三个基本部分:模型(Model),视图(View)和控制器(Co ...

  5. net-snmp配置文件snmp.conf

    master agentxagentaddress UDP:161sysLocation locationsysContact test@example.comsysName TestsysObjec ...

  6. GZDBHelper

    NuGet:GZDBHelper 初始化: public class APIBase : ApiController { protected GZDBHelper.IDatabase db; publ ...

  7. @MarkFan 口语练习录音 20140406 [美女与野兽的口语练习录音]

    大家好,您现在收听的是美女与野兽的口语练习录音 敢于追求,不惧任何挑战,才是勇敢的人生.试想一下,世界上每天有多少人为了梦想,为了生活,甚至是为了别人在不停地奔跑.假若你此刻心中装有梦想,却碍于现实不 ...

  8. Cocos2d-x项目移植到WP8系列之五:播放MP3

    原文链接: http://www.cnblogs.com/zouzf/p/3972549.html 这一块的细节还是不太了解,只是东凑西拼能跑起来而已 1.网上下载lamb库 生成需要的lib库,详情 ...

  9. BYTE、HANDEL、DWORD等的定义

    有时候引入第三方库之后,可能会存在标题的这些变量没有定义,原来这些变量都定义在windows.h里面,包含进去就行了(Qt的MSVC编译器)

  10. INSPIRED启示录 读书笔记 - 第29章 大公司如何创新

    大公司实现创新的方法 20%法则:谷歌的程序员有20%的工作时间可以用来从事创新研究,这个方法最早是从施乐帕克研究所学来的.20%法则鼓励普通员工自己尝试各种想法,让员工打心底愿意倾注更多的激情和汗水 ...