hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0
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<=A i<B i<=1000), meaning that the ith course is available during the time interval (Ai,Bi).
The input ends by N = 0.
Output
Sample Input
1 10
4 5
0
Sample Output
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std; const int maxn=550; struct node
{
int ai,bi;
} task[maxn];
int nn;
bool mark[maxn]; bool cmp(node A, node B)
{
if(A.bi==B.bi) return A.ai<B.ai;
return A.bi<B.bi;
} int solve(int ss)
{
int ans=0;
memset(mark,0,sizeof(mark));
for(int i=ss;i<=task[nn-1].bi;i+=5){
for(int j=0;j<nn;j++){
if(mark[j]) continue;
if(i>=task[j].ai&&i<task[j].bi){
ans++;
mark[j]=1;
break;
}
}
}
return ans;
} int main()
{
int ans;
while(scanf("%d",&nn),nn!=0){
for(int i=0;i<nn;i++) scanf("%d%d",&task[i].ai,&task[i].bi);
sort(task,task+nn,cmp);
ans=0;
for(int i=0;i<5;i++) ans=max(ans,solve(i));
printf("%d\n",ans);
}
}
hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0的更多相关文章
- hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1
F - Computer Virus on Planet Pandora Time Limit:2000MS Memory Limit:128000KB 64bit IO Format ...
- hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0
H - National Day Parade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
- hdu 3696 10 福州 现场 G - Farm Game DP+拓扑排序 or spfa+超级源 难度:0
Description “Farm Game” is one of the most popular games in online community. In the community each ...
- hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1
In geometry the Fermat point of a triangle, also called Torricelli point, is a point such that the t ...
- hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1
F - Rotational Painting Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1
C - To Be an Dream Architect Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0
C - To Be an Dream Architect Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- HDU 3697 Selecting courses(贪心)
题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...
随机推荐
- Python开发【模块】:PyMySQL
PyMySQL 1.安装 [root@localhost ~]# pip install PyMySQL 2.初识 创建数据表结构: mysql> CREATE TABLE `users` ( ...
- Mirror--镜像用户同步
--=========================================--在镜像搭建后,在主库服务器上创建登录,并在数据库上建立对应用户,--数据库中用户被同步到镜像数据库中,但登录是 ...
- Spark的Java API例子详解
package com.hand.study; import scala.Tuple2; import org.apache.spark.SparkConf; import org.apache.sp ...
- 本地blast的安装
1 下载程序 在ftp://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/LATEST/下载 ncbi-blast-2.2.25+-x64-linux.t ...
- 6.3 Controllers -- Managing Dependencies Between Controllers
1. 有时候,特别是当嵌套资源的时候,我们需要两个controllers之间的某种连接.让我们拿这个router当做例子: app/router.js var Router = Ember.Route ...
- cocos代码研究(22)Widget子类Layout学习笔记
理论基础 一个包含控件的容器. 子节点可以根据布局类型重新排序,它还可以开启剪裁,设置背景图像和颜色.继承自Widget,以及LayoutProtocol. 被 HBox, PageView, Rel ...
- hdu 5068 线段树加+dp
这题说的是 有n 层每层 有两个门 每个门 可以到达上一层的两个门,然后求从a 层到达b 层的方案总数, 不能后退, 在同一层中不能从第一个门到达另一层 我们只要我们可以对于每个 区间内 有dp[o] ...
- EF Code First学习笔记:数据库创建(转)
控制数据库的位置 默认情况下,数据库是创建在localhost\SQLEXPRESS服务器上,并且默认的数据库名为命名空间+context类名,例如我们前面的BreakAway.BreakAwayCo ...
- pug 在线文档
https://pugjs.org/zh-cn/api/getting-started.html
- STM32 DMA简述
STM32 DMA简述 DMA (Direct Memory Access) 直接内存存储器,在做数据传输时能够大大减轻CPU的负担. DMA的作用 DMA提供了一个关于数据的高数传输通道,这个通道不 ...