hdoj--5240--Exam()
Exam
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1029 Accepted Submission(s): 511
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.
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.
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).
2
3
3 2 2
5 100 2
7 1000 2
3
3 10 2
5 100 2
7 1000 2
Case #1: NO
Case #2: YES
无脑排序加判断
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
int t,e,l;
}edge[100000];
bool cmp(node s1,node s2)
{
return s1.e<s2.e;
}
int main()
{
int t;
int Case=1;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d%d",&edge[i].t,&edge[i].e,&edge[i].l);
sort(edge,edge+n,cmp);
int sum=0;
int flog=0;
for(int i=0;i<n;i++)
{
sum+=edge[i].t;
if(sum>edge[i].e)
{
flog=1;break;
}
sum+=edge[i].l;
}
printf("Case #%d: ",Case++);
if(flog) printf("NO\n");
else printf("YES\n");
}
return 0;
}
hdoj--5240--Exam()的更多相关文章
- hdu 5240 Exam(贪心)
Exam Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 🔺 Garbage Remembering Exam UVA - 11637()
题目大意:给你N个单词,有两种方法随机排列,一种随机排成一行,另一种随机排成一圈,当两个单词之间的距离在两种排列中都严格小于K时,则这两个单词构成无效单词,问无效单词的期望. 解题思路:首先对于一排单 ...
- 以下C#程序的输出结果是( )。
以下程序的输出结果是( ). using System; namespace HoverTreeTikuConsole { class Program { static void Main(strin ...
- PHP 位运算(&, |, ^, ~, <<, >>)及 PHP错误级别报告设置(error_reporting) 详解
位运算符允许对整型数中指定的位进行求值和操作. 位运算符 例子 名称 结果 $a & $b And(按位与) 将把 $a 和 $b 中都为 1 的位设为 1. $a | $b Or(按位或) ...
- 页面加载完成后,触发事件——trigger()
<button id="btn">点击我</button> <div id="test"></div> 如果页面 ...
- linux/unix 编程手册 fork()函数
父进程通过fork()函数创建子进程,将父进程数据段和栈的内容拷贝到子进程中,子进程执行程序execve创建新程序,调用exit函数退出到等待wait(),挂起父进程, 父子进程享用相同的程序文本段. ...
- setInterval()与clearInterval()的一个有趣小现象
今天在使用setInterval()时,发现了一个有意思的事情 代码如下: var box=document.getElementById("box");//获取id为“box”的 ...
- HTML DOM对象之createElement()方法
今天在学习DOM节点操作时,发现了创建DOM节点的createElement()方法的一个有意思的现象. 代码如下: var box=document.getElementById("box ...
- join()方法之我见
JavaScript join() 方法 定义和用法 join() 方法用于把数组中的所有元素放入一个字符串. 元素是通过指定的分隔符进行分隔的. 语法 arrayObject.join(separa ...
- 转义字符(\)对JavaScript中JSON.parse的影响概述
JSON是一个提供了stringify和parse方法的内置对象,前者用于将js对象转化为符合json标准的字符串,后者将符合json标准的字符串转化为js对象,本文为大家介绍下转义字符对JSON.p ...
随机推荐
- BZOJ 2288 贪心 +链表
思路: 放个题解好吧. http://www.cnblogs.com/zyfzyf/p/4114774.html //By SiriusRen #include <queue> #incl ...
- 大数字运算——1、BigInteger
package com.wh.BigInteger; import java.math.BigInteger; import java.util.Arrays; /** * @author 王恒 * ...
- DDL:对表___table___的相关操作
1) 增加列 语法: alter table 表名 add 列名 类型(长度) 约束; 2) 修改现有列类型.长度和约束 语法:alter table 表名 modify 列名 类型(长度) 约束; ...
- lua math.random()
math.random([n [,m]]) 用法:1.无参调用,产生[0, 1)之间的浮点随机数. 2.一个参数n,产生[1, n]之间的整数. 3.两个参数,产生[n, m]之间的整数. math. ...
- RoIPooling与RoIAlign的区别
一.RoIPooling与RoIAlign 1.1.RoIPooling 通过对Faster RCNN的学习我妈了解的RolPooling可以使生成的候选框region proposal映射产生固定大 ...
- MAVEN学习笔记之私服Nexus(2)
MAVEN学习笔记之私服Nexus(2) 私有服务器搭建 Nexus www.snatype.org下载 snatype-work 是默认nexus存储nexus a:将bin添加到环境中 Admin ...
- how does Array.prototype.slice.call() work?
763 down vote accepted +50 What happens under the hood is that when .slice() is called normally, thi ...
- LightOJ 1422 Halloween Costumes 【 区间dp 】
区间dp的第一题----- 看题解看了好多~~终于看懂了---55555 dp[i][j] 表示第i天到第j天至少需要多少件衣服 那么第i件衣服只被第i天占用的话, dp[i][j] = dp[i+1 ...
- Java中面向对象三大特性之——封装
概述 面向对象编程语言是对客观世界的模拟,客观世界里成员变量都是隐藏在对象内部的,外界无法直接操作和修改. 封装可以被认为是一个保护屏障,防止该类的代码和数据被其他类随意访问.要访问该类的数据,必须通 ...
- LCIS 最长公共上升子序列问题DP算法及优化
一. 知识简介 学习 LCIS 的预备知识: 动态规划基本思想, LCS, LIS 经典问题:给出有 n 个元素的数组 a[] , m 个元素的数组 b[] ,求出它们的最长上升公共子序列的长度. 例 ...