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 ...
随机推荐
- Java 算法-快速幂
1 什么是快速幂? 快速幂,顾名思义就是快速的求次幂,例如:a^b,普通的算法就是累乘,这样的计算方法的时间复杂度就是O(n),而快速幂的方法使得次幂的计算方法的时间复杂度降低到O(logn). 假 ...
- 大规模Docker平台自动化监控之路
本文介绍了通过Monitor,如何实现大规模容器运维平台的自动化监控需求. 尽管Docker技术目前还处于不稳定的发展与标准制定阶段,但这门技术已经呈现了极其火热的增长状态,却已经是不争的实事.到底有 ...
- Java char 和 String 的区别: 字符编码及其存储
一. ASCII码 上个世纪60年代,美国制定了一套字符编码,对英语字符与二进制位之间的关系,做了统一规定.这被称为ASCII码,一直沿用至今.一个字节(8bit)一共 可以用来表示256种不同的状态 ...
- AE Scene开发中的观察者模式
AE SceneGraph中的观察者模式 注意SceneControl不是观察者,它只是一个SceneGraph的拥有者:SceneViewer才是观察者,SceneGraph是被观察对象,同时观察者 ...
- jQuery事件-div的显示隐藏及鼠标的移入移出
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 自动化测试中级篇——LazyAndroid UI自动化测试框架使用指南
原文地址https://blog.csdn.net/iamhuanggua/article/details/53104345 简介 一直以来,安卓UI自动化测试都存在以下两个障碍,一是测试工具Mo ...
- testng日志和报告
TestNG是通过 Listeners 或者 Reporters 生成测试报告. Listeners,即 org.testng.ITestListener 的实现,能够在测试执行过程中发出各种测试结果 ...
- The 2017 China Collegiate Programming Contest, Hangzhou Site Solution
A: Super_palindrome 题面:给出一个字符串,求改变最少的字符个数使得这个串所有长度为奇数的子串都是回文串 思路:显然,这个字符串肯定要改成所有奇数位相同并且所有偶数位相同 那统计一下 ...
- python: 随机选择
想从一个序列中随机抽取若干元素,或者想生成几个随机数. random 模块有大量的函数用来产生随机数和随机选择元素.比如,要想从一个序列中随机的抽取一个元素,可以使用random.choice() : ...
- JavaScript实现Map功能
JavaScript中没有类似Java中的Map集合类的实现,自己做了简单实现,如下: function Map() { this.elements = new Array(); this.size= ...