HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)
Description
You are to find the maximum number of courses that a student can select.
Input
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
题目大意:给n个课程,每个课程有一个选择时间段(ai, bi),只能在这个时间段里面选择。然后你可以在任何时刻开始选课,然后每隔5分钟可以选一门课,问最多选多少门课。
思路:首先开始是越早越好,在8分开始不如在3分就开始。然后枚举5个开始时间,然后对每个时间枚举可以选择的课,选bi最小的(因为bi最小的被后面的时间选中的可能性最小,若bi能在后面被选中那么其他也能在后面被选中)。完全暴力不需要任何优化即可AC。
PS:那个(ai, bi)应该是开区间,不过我们可以选择在0分1秒的时候开始,所以可以看成是[ai, bi)。
代码(31MS):
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = ; int a[MAXN], b[MAXN];
bool sel[MAXN];
int n; int solve() {
int ret = ;
for(int st = ; st < ; ++st) {
memset(sel, , sizeof(sel));
int ans = ;
for(int i = st; i <= ; i += ) {
int best = -;
for(int j = ; j < n; ++j)
if(!sel[j] && a[j] <= i && i < b[j]) {
if(best == -) best = j;
else if(b[j] < b[best]) best = j;
}
if(best != -) {
sel[best] = true;
++ans;
}
}
if(ret < ans) ret = ans;
}
return ret;
} int main() {
while(scanf("%d", &n) != EOF && n) {
for(int i = ; i < n; ++i) scanf("%d%d", &a[i], &b[i]);
printf("%d\n", solve());
}
}
HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)的更多相关文章
- 2010 Asia Fuzhou Regional Contest
A hard Aoshu Problem http://acm.hdu.edu.cn/showproblem.php?pid=3699 用深搜写排列,除法要注意,还有不能有前导零.当然可以5个for, ...
- HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
- HDU 3695 / POJ 3987 Computer Virus on Planet Pandora(AC自动机)(2010 Asia Fuzhou Regional Contest)
Description Aliens on planet Pandora also write computer programs like us. Their programs only consi ...
- HDU 3698 Let the light guide us(DP+线段树)(2010 Asia Fuzhou Regional Contest)
Description Plain of despair was once an ancient battlefield where those brave spirits had rested in ...
- HDU 3696 Farm Game(拓扑+DP)(2010 Asia Fuzhou Regional Contest)
Description “Farm Game” is one of the most popular games in online community. In the community each ...
- HDU 3697 Selecting courses(贪心)
题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...
- 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 题目大意:选课,给出每门课可以的选课时间.自开始选课开始每过五分钟可以选一门课,开始 时间必须小于等于四,问最多可以选 ...
随机推荐
- Extjs treePanel 的treestore重复加载问题解决
在Extjs 4.2.2 中构建一个treePanel 发现设置rootVisible后 ,treeStore中设置的autoLoad:false不启作用,在组件初始化的时候即加载数据源,造成数据重复 ...
- oracle官网下载教程
1.百度搜索oracle 也可以直接点击进入 oracle官网 或直接进入 下载页面 2.选择中文,看的更容易些 3.拉到最下面,选择所有下载和试用 4.选择数据库下载 5.点击下载对 ...
- oracle聚簇表的理解 (转自:https://blog.csdn.net/gumengkai/article/details/51009345 )
Oracle支持两种类型的聚簇:索引聚簇和哈希聚簇 一.索引聚簇表的原理 聚簇:如果一些表有一些共同的列,则将这样一组表存储在相同的数据块中 聚簇还表示把相关的数据存储在同一个块上.利用聚簇,一个块可 ...
- iOS:常用属性、方法
前言:一段时间没接触,很容易就忘记以前的知识.专写一篇,供几个月没接触,拿起却忘记了. 0.宏定义.系统相关 0-1).宏定义.规范 变量: //全局变量通常用小写g来提示 int gNumb=0; ...
- 【TOJ 4493】Remove Digits(单调栈贪心)
描述 Given an N-digit number, you should remove K digits and make the new integer as large as possible ...
- ABAP术语-Field
Field 原文:http://www.cnblogs.com/qiangsheng/archive/2008/02/01/1061244.html Name in an ABAP program f ...
- jsp传参 servlet接收中文乱码问题
在公司实习了8个月,一直都是做android和h5的,但是发现做程序连一点服务都不会该怎么办,所以最近开始学起了java,不知道是不是因为框架学多了,现在看起springmvc框架比以前看起来简单太多 ...
- 操作BOM
BOM的作用是将相关的元素组织包装起来,提供给程序设计人员使用,从而降低开发人员的劳动量,提高设计Web页面的能力. 整个window对象是整个BOM的核心. 通过BOM可实现的功能: 弹出新的浏览器 ...
- Python学习:2.Python集成学习环境(IDE)Pycharm的安装配置以及激活方
一.下载Pycharm Pycharm作为Python现在最流行的集成开发环境,我们今后的Python的学习也就使用Pycharm进行,那今天我们就讲一下Pycharm的安装配置以及激活 1.我们首先 ...
- Ubuntu装完后要做的几件事
Ubuntu装完后要做的几件事 改hosts 无论哪里,改hosts都是第一件事,没hosts咋google.没google咋活.在终端输入命令 sudo gedit /etc/hosts在# The ...