BZOJ3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 55 Solved: 34
[Submit][Status]
Description
Being a fan of all cold-weather sports (especially those involving cows), Farmer John wants to record as much of the upcoming winter Moolympics as possible. The television schedule for the Moolympics consists of N different programs (1 <= N <= 150), each with a designated starting time and ending time. FJ has a dual-tuner recorder that can record two programs simultaneously. Please help him determine the maximum number of programs he can record in total.
给出n个区间[a,b).有2个记录器.每个记录器中存放的区间不能重叠.
求2个记录器中最多可放多少个区间.
Input
* Line 1: The integer N.
* Lines 2..1+N: Each line contains the start and end time of a single program (integers in the range 0..1,000,000,000).
Output
* Line 1: The maximum number of programs FJ can record.
Sample Input
0 3
6 7
3 10
1 5
2 8
1 9
INPUT DETAILS: The Moolympics broadcast consists of 6 programs. The first runs from time 0 to time 3, and so on.
Sample Output
OUTPUT DETAILS: FJ can record at most 4 programs. For example, he can record programs 1 and 3 back-to-back on the first tuner, and programs 2 and 4 on the second tuner.
HINT
Source
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int now[],n,ans;
struct rec{int x,y;}a[maxn];
inline bool cmp(rec a,rec b)
{
return a.y<b.y;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n)a[i].x=read(),a[i].y=read();
sort(a+,a+n+,cmp);
now[]=now[]=;
for1(i,n)
{
if(a[i].x>=now[])ans++,now[]=a[i].y;
else if(a[i].x>=now[])ans++,now[]=a[i].y;
if(now[]>now[])swap(now[],now[]);
}
printf("%d\n",ans);
return ;
}
BZOJ3433: [Usaco2014 Jan]Recording the Moolympics的更多相关文章
- 3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 137 S ...
- 【BZOJ】3433: [Usaco2014 Jan]Recording the Moolympics (贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=3433 想了好久啊....... 想不出dp啊......sad 后来看到一英文题解......... ...
- BZOJ 3433 [Usaco2014 Jan]Recording the Moolympics:贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3433 题意: 给出n个区间[a,b). 有两个记录器,每个记录器中存放的区间不能重叠. 求 ...
- 【bzoj 3433】{Usaco2014 Jan} Recording the Moolympics(算法效率--贪心)
题意:给出n个区间[a,b),有2个记录器,每个记录器中存放的区间不能重叠.求2个记录器中最多可放多少个区间. 解法:贪心.只有1个记录器的做法详见--关于贪心算法的经典问题(算法效率 or 动态规划 ...
- [USACO14JAN]Recording the Moolympics
题目描述 Being a fan of all cold-weather sports (especially those involving cows), Farmer John wants to ...
- 【BZOJ】3432: [Usaco2014 Jan]Cross Country Skiing (bfs+二分)
http://www.lydsy.com/JudgeOnline/problem.php?id=3432 题目说要相互可达,但是只需要从某个点做bfs然后判断其它点是否可达即可. 原因太简单了.... ...
- BZOJ 3430: [Usaco2014 Jan]Ski Course Rating(并查集+贪心)
题面 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 136 Solved: 90 [Submit][Status][Discuss] Descript ...
- bzoj3431 [Usaco2014 Jan]Bessie Slows Down
Description [Brian Dean, 2014] Bessie the cow is competing in a cross-country skiing event at the wi ...
- BZOJ 3432: [Usaco2014 Jan]Cross Country Skiing (二分+染色法)
还是搜索~~可以看出随着D值的增大能到达的点越多,就2分d值+染色法遍历就行啦~~~ CODE: #include<cstdio>#include<iostream>#incl ...
随机推荐
- kubernetes组件
kubernetes组件 @(马克飞象)[k8s] 组件 kubernetes除了必备的dns和网络组件外,官方推出大量的cluster-monitoring,dashboard,fluentd-el ...
- hibernate初涉
好久都不曾写写总结一些东西了,惰性真的是令人难以克制!虽然和许多北漂族一样,艰苦而又迷茫,但是我总能找到一些方向,一点期盼,因为你就我的目标.我会坚持下去,重拾青春的热血,既然人生如戏,那我不当猪脚. ...
- java环境下的数据库读写分离
方案很多:阿里的中间件cobar.aop注解方式.com.mysql.jdbc.ReplicationDriver读写分离驱动MySQL数据库的同步. MySQL是开源的关系型数据库系统.主从同步复制 ...
- [Javascript] Advanced Reduce: Additional Reducer Arguments
Sometimes we need to turn arrays into new values in ways that can't be done purely by passing an acc ...
- PHP函数的默认参数
<?php /** * 函数的参数个数任意 */function foo() { $args = func_get_args(); static $i = 0; //统计参数个数 /* fore ...
- Java – 4 Security Vulnerabilities Related Coding Practices to Avoid---reference
This article represents top 4 security vulnerabilities related coding practice to avoid while you ar ...
- Cross-origin resource sharing--reference
Cross-origin resource sharing (CORS) is a mechanism that allows many resources (e.g., fonts, JavaScr ...
- CXF WebService整合Spring
转自http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html 首先,CXF和spring整合需要准备如下jar包文件: 这边我是用Spr ...
- Xml序列化自引用/循环引用问题2
1.类定义: public class Student { public int ID { get; set; } public string Name { get; set; } //[XmlIgn ...
- Arcgis Android 基本概念 - 浅谈
MapView MapView 是 Android 中 ViewGroup的子类,也是 ArcGIS Runtime SDK for Android 中的地图容器,与很多 ArcGIS API ...