1664: [Usaco2006 Open]County Fair Events 参加节日庆祝
1664: [Usaco2006 Open]County Fair Events 参加节日庆祝
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 255 Solved: 185
[Submit][Status][Discuss]
Description
Farmer John has returned to the County Fair so he can attend the special events (concerts, rodeos, cooking shows, etc.). He wants to attend as many of the N (1 <= N <= 10,000) special events as he possibly can. He's rented a bicycle so he can speed from one event to the next in absolutely no time at all (0 time units to go from one event to the next!). Given a list of the events that FJ might wish to attend, with their start times (1 <= T <= 100,000) and their durations (1 <= L <= 100,000), determine the maximum number of events that FJ can attend. FJ never leaves an event early.
有N个节日每个节日有个开始时间,及持续时间. 牛想尽可能多的参加节日,问最多可以参加多少. 注意牛的转移速度是极快的,不花时间.
Input
* Line 1: A single integer, N.
* Lines 2..N+1: Each line contains two space-separated integers, T and L, that describe an event that FJ might attend.
Output
* Line 1: A single integer that is the maximum number of events FJ can attend.
Sample Input
1 6
8 6
14 5
19 2
1 8
18 3
10 6
INPUT DETAILS:
Graphic picture of the schedule:
11111111112
12345678901234567890---------这个是时间轴.
--------------------
111111 2222223333344
55555555 777777 666
这个图中1代表第一个节日从1开始,持续6个时间,直到6.
Sample Output
OUTPUT DETAILS:
FJ can do no better than to attend events 1, 2, 3, and 4.
HINT
Source
题解:一个考得烂了的贪心,很经典的最多不向交区间问题而已
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n:longint;
a:array[..,..] of longint;
procedure swap(var x,y:longint);
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
procedure sort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;j:=r;x:=a[(l+r) div ,];y:=a[(l+r) div ,];
repeat
while (a[i,]<x) or ((a[i,]=x) and (a[i,]>y)) do inc(i);
while (a[j,]>x) or ((a[j,]=x) and (a[j,]<y)) do dec(j);
if i<=j then
begin
swap(a[i,],a[j,]);
swap(a[i,],a[j,]);
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
begin
readln(n);
for i:= to n do readln(a[i,],a[i,]);
for i:= to n do a[i,]:=a[i,]+a[i,]-;
sort(,n);l:=;
for i:= to n do if a[i,]<>a[l,] then
begin
inc(l);
a[l,]:=a[i,];
a[l,]:=a[i,];
end;
n:=l;l:=;k:=;
for i:= to n do
if a[i,]>l then
begin
inc(k);
l:=a[i,];
end;
writeln(k);
readln;
end.
最新文章
- CSS各种定位详解
- iOS底层基础知识-文件目录结构
- UVa 11464 - Even Parity
- Linux Mint SmoothTask2的安装方法
- Apache、Lighttpd、Nginx 三种web服务器对比
- x264源代码简单分析:x264命令行工具(x264.exe)
- adduser与useradd的区别
- Windows 的命令行安装Scoop程序管理工具
- python1114string_test
- 学习笔记之Everything
- thinkphp3.2集成QRcode生成二维码
- 基于 WPF 平台的 ActiveReports Viewer控件
- jdk 动态代理实现对目标对象的增强
- mysql 中只能使用 localhost 登录,用ip不能登陆
- linux中chmod与chown两个命令详解
- linux kernel的中断子系统之(三):IRQ number和中断描述符【转】
- mac 安装mysql 修改密码
- Python中各种进制之间的转化
- 在windows上安装和启动Elasticseach、Kibana
- Node.js 使用JWT进行用户认证
热门文章
- Maven与Antx(整理)
- pureMVC介绍及学习
- 支付宝 Android 版使用的开源组件
- Crontab could not create directory .ssh
- C++ 头文件系列(unordered_map、unordered_set)
- ArcGIS API for JavaScript 4.2学习笔记[3] 官方第二章Mapping and Views概览与解释
- js原生轮播图
- Python学习--16 正则表达式
- Web Worker无阻塞UI的牛逼技术,html5,可惜无法敢于UI
- jvm垃圾收集小记