HDOJ3697 Selecting courses[贪心]
来源:互联网 发布:域名怎么申请域名邮箱 编辑:程序博客网 时间:2024/06/06 20:22
Problem Description
A new Semester is coming and students are troubling for selecting courses. Students select their course on the web course system. There are n courses, the ith course is available during the time interval (Ai,Bi). That means, if you 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.
You are to find the maximum number of courses that a student can select.
Input
There are no more than 100 test cases.
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.
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.
Output
For each test case output a line containing an integer indicating the maximum number of courses that a student can select.
Sample Input
21 104 50
Sample Output
2
题意:给n门课的选课开始时间和截止时间,你可以从任意时间开始,每隔五分钟选一门课,问最多能选多少课。只能在间隔五分钟的那个时间点选课,如果选不了就只能等到下一个五分钟。(刚好在课程开放时间边界也是不能选的)
这相当与是用一堆间隔为5的叉子去叉,看能叉中多少个。只需从0-5枚举开始时间即可。给的时间都是整数,边界又不能选,可以从0.5到4.5来枚举,防止边界判断有误。
就按结束时间排个序,找的时候就找第一门在时间范围内且没被选的就好。
#include<iostream>#include<cassert>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<string>#include<iterator>#include<cstdlib>#include<vector>#include<stack>#include<queue>#include<map>#include<set>using namespace std;#define debug(x) cout<<"debug "<<x<<endl;#define rep(i,f,t) for(int i = (f),_end_=(t); i <= _end_; ++i)#define rep2(i,f,t) for(int i = (f),_end_=(t); i < _end_; ++i)#define dep(i,f,t) for(int i = (f),_end_=(t); i >= _end_; --i)#define dep2(i,f,t) for(int i = (f),_end_=(t); i > _end_; --i)#define clr(c, x) memset(c, x, sizeof(c) )typedef long long int64;const int INF = 0x5f5f5f5f;const double eps = 1e-8;//*****************************************************int n;#define F first#define S secondtypedef pair<int,int> P;P a[330];bool vis[330];int maxt;int fn(double t){ rep(i,1,n){ if(vis[i])continue; if(a[i].F < t && t < a[i].S)return i; } return 0;}bool cmp(const P &p1,const P &p2){return p1.S < p2.S; }int xuan(double tm){clr(vis,0);sort(a+1,a+n+1,cmp);int ans = 0;for(int i; tm < maxt; tm += 5){if( i = fn(tm) ){vis[i] = 1;++ans;}}return ans;}int main(){ a[0].S = INF; while(scanf("%d",&n), n){ maxt = 0; rep(i,1,n){ scanf("%d%d",&a[i].F,&a[i].S); if(a[i].S > maxt)maxt = a[i].S; } int ans = 0; for(double i = 0.5; i < 5; i += 0.5){ int tmp = xuan(i); ans = max(ans,tmp); } printf("%d\n",ans); } return 0;}
0 0
- HDOJ3697 Selecting courses[贪心]
- Hdoj 3697 Selecting courses 【贪心】
- hdu3697 Selecting courses (贪心+暴力)
- 简单贪心-hdu-3697-Selecting courses
- HDU 3697 Selecting courses (贪心)
- hdu 3697 Selecting courses (暴力+贪心)
- HDU 3697 Selecting courses(贪心)
- Hdu 3697 Selecting courses(贪心+暴力)
- hdu 3697 Selecting courses(贪心)
- HDU 3697 Selecting courses(贪心)
- HDU 3697 Selecting courses 选课(AC代码)贪心
- HDU-3697-Selecting courses(贪心+优先队列)
- PKU_2239 Selecting Courses
- pku2239 Selecting Courses
- POJ 2239 Selecting Courses
- poj 2239 Selecting Courses
- POJ-2239 Selecting Courses
- 二分匹配 Selecting Courses
- App数据层设计及云存储使用指南
- 输出5个字符串中最大的字符串。
- 分段机制
- win7常用快捷键
- Linux使用Composer安装yii2的方法及bug处理
- HDOJ3697 Selecting courses[贪心]
- 25个必须记住的SSH命令
- 嵌入式linux内核制作
- adb打印指定tag的logcat
- 第十五周项目 指针求解两数中较大的数和较小的数
- 数字梯形问题
- (转自Mitchell Chu's Blog)定义文档兼容性,让IE按指定的版本解析我们的页面
- Android入门笔记 - 界面开发 - ProgressBar,Handler
- 大数相加-大数取余-nyoj-AC_mm玩dota