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 ...
随机推荐
- LOL喷子专用自动骂人工具,2018更新完整版!
软件截图 软件说明: 先进入游戏 打开程序 Z开启/C关闭 下载地址:密码 yjnm
- leetcode_654. Maximum Binary Tree
https://leetcode.com/problems/maximum-binary-tree/ 给定数组A,假设A[i]为数组最大值,创建根节点将其值赋为A[i],然后递归地用A[0,i-1]创 ...
- $("[lay-id='demo'] tbody tr[data-index=0]") 查找某行layui table
$("[lay-id='demo'] tbody tr[data-index=0]")
- CAD使用DeleteXData删除数据(com接口)
主要用到函数说明: MxDrawEntity::DeleteXData 删除扩展数据,详细说明如下: 参数 说明 pzsAppName 删除的扩展数据名称,如果为空,删除所有扩展数据 c#代码实现如下 ...
- MFC程序最小化到系统托盘及其响应函数
预备知识: Windows API函数: WINSHELLAPI BOOL WINAPI Shell_NotifyIcon( DWORD dwMessage, PNOTIFYICONDATA pnid ...
- vue slot的使用介绍
插槽:slot (不知道我这样理解是不是对的,欢迎大佬指点) 具体是什么样子的,请看例子说明 父组件代码 子组件代码 结果 可以看到 ,结果是父组件里面内容显示了,子组件内容显示了,但是在父组件中插入 ...
- eclipse perl配置
先下载jdk,如果jdk装的是32位,eclipse也要下载32位的,64位也是一样.我用的是jdk7 64位. 下载eclipse,去官网上下载最新的http://www.eclipse.org/d ...
- Quartz --quartz.properties
quartz.properties 如果项目中没有该配置文件,则会去jar包中读取自带配置文件 默认的配置如下 # Default Properties file for use by StdSche ...
- SQlServer中的MD5加密
SELECT sys.fn_varbintohexstr(HASHBYTES('MD5', '我'));
- Vertex&Frag
一.Vertex&Frag 包含Vertex&Fragment 的Shader叫做顶点&像素着色器,在Vertex的功能函数中,我们侧重于几何计算,如纹理坐标,顶点坐标等:在F ...