Hdoj 3697 Selecting courses 【贪心】
Selecting courses
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 62768/32768 K (Java/Others)
Total Submission(s): 2082 Accepted Submission(s): 543
want to select the ith course, you must select it after time Ai and before time Bi. Ai and Bi are all in minutes. A student can only try to select a course every 5 minutes, but he can start trying at any time, and try as many times as he wants. For example,
if you start trying to select courses at 5 minutes 21 seconds, then you can make other tries at 10 minutes 21 seconds, 15 minutes 21 seconds,20 minutes 21 seconds… and so on. A student can’t select more than one course at the same time. It may happen that
no course is available when a student is making a try to select a course
You are to find the maximum number of courses that a student can select.
The first line of each test case contains an integer N. N is the number of courses (0<N<=300)
Then N lines follows. Each line contains two integers Ai and Bi (0<=Ai<Bi<=1000), meaning that the ith course is available during the time interval (Ai,Bi).
The input ends by N = 0.
2
1 10
4 5
0
2
题意:有n门课,选课时有以下rule:
1:每种课都有起始和结束,必须在之内选取。
2:每次选取之后5分钟后不能再选课。
先依照结束时间从小到大排序,由于是每过五分钟才干够选。那么我们仅仅须要枚举前四个时间,看是否在课程的起始与结束时间之内。就能够了。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
const int M = 1100;
using namespace std; struct node{
int l, r;
}s[M];
int n;
bool vis[M]; bool cmp(node a, node b){
return a.r < b.r;
} int f(double x){
memset(vis, 0, sizeof(vis));
int res = 0;
for(double d = x; d < M; d += 5){
for(int i = 0; i < n; ++ i){
if(!vis[i]&&d > s[i].l &&s[i].r > d){
res++;
vis[i] = 1; break;
}
}
}
return res;
} int main(){
while(scanf("%d", &n), n){
for(int i = 0; i < n; ++ i) scanf("%d%d", &s[i].l, &s[i].r);
sort(s, s+n, cmp);
int ans = 0;
for(double i = 0.5; i < 5; ++ i){
ans = max(ans, f(i));
}
printf("%d\n", ans);
}
return 0;
}
Hdoj 3697 Selecting courses 【贪心】的更多相关文章
- HDU 3697 Selecting courses(贪心)
题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...
- hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0
Description A new Semester is coming and students are troubling for selecting courses. Students ...
- HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)
Description A new Semester is coming and students are troubling for selecting courses. Students ...
- hdu 3697 Selecting courses (暴力+贪心)
Selecting courses Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 62768/32768 K (Java/Others ...
- HDU 3697 Selecting courses 选课(贪心)
题意: 一个学生要选课,给出一系列课程的可选时间(按分钟计),在同一时刻只能选一门课程(精确的),每隔5分钟才能选一次课,也就是说,从你第一次开始选课起,每过5分钟,要么选课,要么不选,不能隔6分钟再 ...
- HDU - 3697 Selecting courses
题目链接:https://vjudge.net/problem/HDU-3697 题目大意:选课,给出每门课可以的选课时间.自开始选课开始每过五分钟可以选一门课,开始 时间必须小于等于四,问最多可以选 ...
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- poj——2239 Selecting Courses
poj——2239 Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10656 A ...
- POJ-2239 Selecting Courses,三维邻接矩阵实现,钻数据空子。
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Description It is well known that ...
随机推荐
- vue2.0 v-model指令
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 新萝卜家园Ghost版Win10系统X32极速装机版2015年4月
来自:系统妈,系统下载地址:http://www.xitongma.com/windows10/2015-03-30/6638.html 新萝卜家园Ghost Win10 X32 10041电脑城极速 ...
- 如何选安卓android|linux系统开发板,简化学习难度,缩短开发进程
平台一:iTOP-4412精英版 系统支持:Android 4.0.3系统 / Android 4.4系统 / Linux + Qt系统 / Ubuntu12.04系统 开发板特点:Cortex-A ...
- [转载]迅为4418开发板Qt移植移动4G模块第一部分
本文转自迅为论坛:http://topeetboard.com 平台:iTOP-4418开发板 1.首先要配置内核,这个一步和Android系统移植3G或者4G模块是一样的.一般模块的 ...
- 怎样在nexus 中 搜索到远程maven仓库中的jar 文件
怎样在nexus 中 搜索到远程maven仓库中的jar 文件 url: http://www.oschina.net/question/95712_21999 点击Administration菜单下 ...
- CE工具里自带的学习工具--第六关
这一步原理: 相当于有一个变量 int a=100; int *p=&a; 点击修改值, 在ce工具里可以找到a的值. a的地址. 但是在实际代码里,并不是这么处理的, 是 通过指针改变这 ...
- 给SVN控制的项目添加忽略文件/文件夹
忽略目录其实有些像建立一个文件夹,但却不放入版本控制.如果不加入版本控制又会在svn status命令中显示出来,很不方便,所以可以设置本文件夹属性,让它既加入版本控制,又忽略其变化 未加入控制的文件 ...
- zabbix4.2学习笔记--TCP状态监控
Tcp的连接状态对于我们web服务器来说是至关重要的,尤其是并发量ESTAB:或者是syn_recv值,假如这个值比较大的话我们可以认为是不是受到了攻击(例如SYN攻击),或是是time_wait值比 ...
- redis新特性
摘自<redis 4.xcookbook> 从实例重启同步] 故障切换同步] 4.0之前从实例主键过期bug redis4新特性 Memory Command Lazy Free PSYN ...
- 第3节 mapreduce高级:8、9、自定义分区实现分组求取top1
自定义GroupingComparator求取topN GroupingComparator是mapreduce当中reduce端的一个功能组件,主要的作用是决定哪些数据作为一组,调用一次reduce ...