[USACO14JAN]Recording the Moolympics
题目描述
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 (1 <= N <= 150)个节目,每个节目都有开始和结束时间。农民约翰有两台录像机,请计算他最多可以录制多少个节目。
输入输出格式
输入格式:
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).
输出格式:
- Line 1: The maximum number of programs FJ can record.
输入输出样例
6
0 3
6 7
3 10
1 5
2 8
1 9
4
说明
INPUT DETAILS:
The Moolympics broadcast consists of 6 programs. The first runs from time
0 to time 3, and so on.
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.
Source: USACO 2014 January Contest, Silver
错误贪心:两遍线段覆盖
错因:推样例
正确贪心:先按右端点从小到大排序,如果这个线段两台录像机都可以给,给结束时间晚的那个
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
int s,t;
}e[];
bool cmp(node p,node q)
{
return p.t<q.t;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].s,&e[i].t);
sort(e+,e+n+,cmp);
int ans=,end1=,end2=;
for(int i=;i<=n;i++)
{
if(e[i].s>=end1 && e[i].s>=end2)
{
end1>end2 ? end1=e[i].t : end2=e[i].t;
ans++;
}
else if(e[i].s>=end1)
{
end1=e[i].t;
ans++;
}
else if(e[i].s>=end2)
{
end2=e[i].t;
ans++;
}
}
printf("%d",ans);
}
[USACO14JAN]Recording the Moolympics的更多相关文章
- BZOJ3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 55 So ...
- 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 动态规划 ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 关于贪心算法的经典问题(算法效率 or 动态规划)
如题,贪心算法隶属于提高算法效率的方法,也常与动态规划的思路相挂钩或一同出现.下面介绍几个经典贪心问题.(参考自刘汝佳著<算法竞赛入门经典>).P.S.下文皆是我一个字一个字敲出来的,绝对 ...
- P2255 [USACO14JAN]记录奥林比克Recording the M…
P2255 [USACO14JAN]记录奥林比克Recording the M… 题目描述 Being a fan of all cold-weather sports (especially tho ...
随机推荐
- Scrum立会报告+燃尽图(十月十八日总第九次):功能细化与数据库设计
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246 项目地址:https://git.coding.net/zhang ...
- txt文件存储问题
一.实际大小与占用空间不一致: 1.占用空间和磁盘有关,一般磁盘存储最小大小为4kb(4096字节). 2.当txt文件中仅有1个数字‘5’的时候,大小显示为1个字节(属性看,列表详细不精确),占用空 ...
- 01—为什么使用java
Java解决的问题 1.指针问题 java里面没有指针,用引用解决指针问题,但是引用是一种限制的指针,不能参与整数运行和指向任意位置的内存,并且不用显示回收对象 引用地址:http://blog.cs ...
- centos7环境下mysql安装
1.去官网下载合适的yum源安装包 https://dev.mysql.com/downloads/repo/yum/ 2.yum 本地安装 命令:yum localinstall mysql57-c ...
- Windows上安装、配置MySQL的常见问题
一,MySQL的下载安装 MySQL的安装过程就不说了,基本上和一般软件的安装过程没什么两样,就是一路点next,设置的root用户的密码要牢记.具体教程可以参考:http://jingyan.bai ...
- [mysqld_safe]centos7 mysql 安装与配置
查资料发现是CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了. 有两种解决办法: 安装mariadb [root@a ~]# yum install mar ...
- ngx_http_rewrite_module(重定向)
1:指定rewrite规则 rewrite regex replacement [flag]; 什么是rewrite规则:If the specified regular expression m ...
- 5th 各组作品alpha发布体会
1. 俄罗斯方块 武志远 可以进行游戏,界面很友好,游戏运行也很流畅,并找到两名同学现场体验,游戏完成度很好. 2. 连连看游戏 张金生 可以进行游戏,实现了背景音乐播放等附加功能,界面清晰 ...
- phpcms前端模板目录与文件结构分析图【templates】
phpcms前端模板目录与文件结构分析图[templates] 原文地址:http://www.iphpcms.net/phpcms-ziliao/2015_14.html
- Spring事务管理Transaction【转】
Spring提供了许多内置事务管理器实现(原文链接:https://www.cnblogs.com/qiqiweige/p/5000086.html): DataSourceTransactionMa ...