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 ...
随机推荐
- WebSocket 的一些简单页面推送使用
因为做通信项目的时候,需要实时获取每个分机的当前状态,发现websocket还不错,只是对浏览器的要求比较高, 针对特定用户推送消息,网上有一些 public class GetHttpSession ...
- QList模板类常用接口函数
插入操作:insert()函数原型:void QList::insert(int i, const T &value) 在索引后插入值 i:索引 value:插入值 Example: QLis ...
- Mysql,Oracle使用rollup函数完成行列统计
时间 2014-02-25 00:05:38 ITeye-博客 原文 http://53873039oycg.iteye.com/blog/2021445 主题 MySQLOracle数据库 昨天 ...
- LeetCode1-5
Leetcode1: Given an array of integers, return indices of the two numbers such that they add up to a ...
- ERROR 1133 (42000): Can't find any matching row in the user table
环境:操作系统:Redhat 7.5 x86-64 数据库版本MySQL 5.7.25 现象:ERROR 1133 (42000): Can't find any matching row in th ...
- css hack解决方案
现在大家做项目的时候估计很多都已经不怎么考虑兼容问题,大多数的公司都已经舍弃ie7.8了,都是从ie9+开始,所以说不会有那么多的兼容问题需要去解决了,但是由于本人力求完美的工作习惯,做项目的时候还是 ...
- 安装配置Keepalived
一.在haproxy容器安装Keepalived 1.进入haproxy容器: docker exec -it h1 bash 2.apt-get update(因为haproxy容器为Ubuntu) ...
- assert.throws()函数详解
assert.throws(block[, error][, message]) Node.js FS模块方法速查 期望 block 函数抛出一个错误. 如果指定 error,它可以是一个构造函数.正 ...
- linux文件及目录的权限管理
一.文件的权限 1.文件权限的查看 命令:ls -l 可以使用ll命令代替 ls -l 2.ls -l 所包含的信息 (1)权限信息 (-rw-r--r-- ) 一共有10位 a.第一位:表示文件信息 ...
- rbac组件之数据库设计(一)
rbac是基于角色的权限设计,一共包含六张表,具体的表设计如下: from django.db import models class Menu(models.Model): "" ...