3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 137 Solved: 89
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
6 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
4 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
题解:(呵呵哒我会告诉你我的第一反应是网络流?)
其实仔细看看后发现还是个贪心,只不过现在是两个容器= =,然后就是经典的右边界排序后O(n)乱搞了
1 /**************************************************************
2 Problem: 3433
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:0 ms
7 Memory:304 kb
8 ****************************************************************/
9
10 var
11 i,j,k,l,m,n,ans,l1,l2:longint;
12 a:array[0..10000,1..2] of longint;
13 procedure swap(var x,y:longint);
14 var z:longint;
15 begin
16 z:=x;x:=y;y:=z;
17 end;
18 procedure sort(l,r:longint);
19 var i,j,x,y:longint;
20 begin
21 i:=l;j:=r;x:=a[(l+r) div 2,2];
22 repeat
23 while a[i,2]<x do inc(i);
24 while a[j,2]>x do dec(j);
25 if i<=j then
26 begin
27 swap(a[i,1],a[j,1]);
28 swap(a[i,2],a[j,2]);
29 inc(i);dec(j);
30 end;
31 until i>j;
32 if i<r then sort(i,r);
33 if l<j then sort(l,j);
34 end;
35
36 begin
37 readln(n);
38 for i:=1 to n do readln(a[i,1],a[i,2]);
39 sort(1,n);
40 for i:=1 to n do
41 begin
42 if (a[i,1]>=l1) then
43 begin
44 l1:=a[i,2];
45 inc(ans);
46 end
47 else if (a[i,1]>=l2) then
48 begin
49 l2:=a[i,2];
50 inc(ans);
51 end;
52 if l1<l2 then swap(l1,l2);
53 end;
54 writeln(ans);
55 readln;
56 end.
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 知了超细讲解Django打造大型企业官网学习记录,02diango url 笔记
- 直播卖货小程序源码中,商品分类页面是如何实现的
- python requests.session验证码登录应用实战,爱站关键词挖掘采集
- 【淘宝】python的淘宝秒杀抢购下单源码参考
- Python素材下载爬虫,ui素材下载爬取采集源码
- Python与seo的应用,sitemap.xml文件制作工具源码
- 关键词爬虫,Python花瓣画板关键词采集存储数据库
- 电商商品爬虫,亚马逊amazon采集源码
- Python tk例子,古董音乐播放器exe
- 爬虫例子,Python多线程爬虫例子案例
- 【爬虫】花瓣图片爬虫,Python图片采集下载源码
- Python大作网图片采集下载,多线程图片爬虫
- Python素材下载爬虫,多线程rar下载爬虫
- 一个简单的图片爬虫,Python图片采集下载
- 百度统计后台总是被广告骚扰?看看应用python是如何实现的