HDOJ 5240 Exam
来源:互联网 发布:身份证恶搞软件 编辑:程序博客网 时间:2024/05/21 23:31
题目大意:一个人要去考试,一门考试要花r小时准备,e小时后考,考试持续l小时,给出一组数据,问能不能完成所有的考试?
算法分析:这是个水题,按照先考先复习的思路,按照考试时间排序,只要r>e就输出NO,否则的话就把下一轮考试的时间减去此次考试的e+l,再循环判断。
实现代码如下:
#include <iostream>#include <algorithm>using namespace std;#define MAX 100005struct Exam { int r, e, l; bool operator<(const Exam &ex) const { return e < ex.e; }} a[MAX];int n;int main() { //freopen("1.txt","r",stdin); int t; cin >> t; int cas = 0; while (t--) { int flag = 1; cin >> n; for (int i = 0; i < n; ++i) scanf("%d%d%d", &a[i].r, &a[i].e, &a[i].l); sort(a,a+n); for (int j = 0; j < n; ++j) { if (a[j].r > a[j].e) { printf("Case #%d: NO\n", ++cas); flag = 0; } else { a[j+1].e -= a[j].e + a[j].l; } } if (flag) printf("Case #%d: YES\n",++cas); }}
0 0
- hdoj 5240 Exam 【模拟】
- hdoj--5240--Exam()
- HDOJ 5240 Exam(水)
- hdoj 5240 Exam
- hdoj 5240 Exam
- hdoj 5240 Exam【贪心】
- HDOJ 5240 Exam
- HDOJ 5240 Exam
- HDOJ 5240 Exam 【简单模拟】
- HDOJ 5240 Exam (贪心)
- hdoj Exam 5240 (简单逻辑题)
- HDOJ 5240 Exam 【sort排序&&模拟】
- HDOJ 4473 Exam 暴力枚举
- HDU 4473 HDOJ Exam (推理,5级)
- HDU 5240 Exam
- HDU 5240 Exam
- HDU 5240 Exam
- 杭电5240Exam
- ldap创建主从和主主复制协议
- LeetCode Triangle
- (一)启动进程Init
- MyBatis--HelloWorld
- 兔子数
- HDOJ 5240 Exam
- Java多线程:线程状态
- poj3213(特殊的矩阵乘法)
- 下一个风口就是硬科技,抓住机遇,中国能重返世界之巅
- Web AppBuilder for ArcGIS(开发版)系列教程 1
- MyBatis Generator 通过xml生成,有日志但是没有生成文件成功的问题
- 1. Two Sum
- windows 7 composer的安装
- 不要在linux上启用net.ipv4.tcp_tw_recycle参数