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

7
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

4

OUTPUT DETAILS:

FJ can do no better than to attend events 1, 2, 3, and 4.

HINT

 

Source

Silver

题解:一个考得烂了的贪心,很经典的最多不向交区间问题而已

  1. /**************************************************************
  2. Problem:
  3. User: HansBug
  4. Language: Pascal
  5. Result: Accepted
  6. Time: ms
  7. Memory: kb
  8. ****************************************************************/
  9.  
  10. var
  11. i,j,k,l,m,n:longint;
  12. a:array[..,..] 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 ,];y:=a[(l+r) div ,];
  22. repeat
  23. while (a[i,]<x) or ((a[i,]=x) and (a[i,]>y)) do inc(i);
  24. while (a[j,]>x) or ((a[j,]=x) and (a[j,]<y)) do dec(j);
  25. if i<=j then
  26. begin
  27. swap(a[i,],a[j,]);
  28. swap(a[i,],a[j,]);
  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. begin
  36. readln(n);
  37. for i:= to n do readln(a[i,],a[i,]);
  38. for i:= to n do a[i,]:=a[i,]+a[i,]-;
  39. sort(,n);l:=;
  40. for i:= to n do if a[i,]<>a[l,] then
  41. begin
  42. inc(l);
  43. a[l,]:=a[i,];
  44. a[l,]:=a[i,];
  45. end;
  46. n:=l;l:=;k:=;
  47. for i:= to n do
  48. if a[i,]>l then
  49. begin
  50. inc(k);
  51. l:=a[i,];
  52. end;
  53. writeln(k);
  54. readln;
  55. end.

1664: [Usaco2006 Open]County Fair Events 参加节日庆祝的更多相关文章

  1. BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )

    先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开 ...

  2. 【BZOJ】1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(线段树+dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1664 和之前的那题一样啊.. 只不过权值变为了1.. 同样用线段树维护区间,然后在区间范围内dp. ...

  3. bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】

    把长度转成右端点,按右端点排升序,f[i]=max(f[j]&&r[j]<l[i]),因为r是有序的,所以可以直接二分出能转移的区间(1,w),然后用树状数组维护区间f的max, ...

  4. bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝

    Description Farmer John has returned to the County Fair so he can attend the special events (concert ...

  5. [Usaco2006 Open]County Fair Events 参加节日庆祝

    Description Farmer John has returned to the County Fair so he can attend the special events (concert ...

  6. 【动态规划】bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝

    将区间按左端点排序. f(i)=max{f(j)+1}(p[j].x+p[j].y<=p[i].x && j<i) #include<cstdio> #incl ...

  7. County Fair Events

    先按照结束时间进行排序,取第一个节日的结束时间作为当前时间,然后从第二个节日开始搜索,如果下一个节日的开始时间大于当前的时间,那么就参加这个节日,并更新当前时间 #include <bits/s ...

  8. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  9. 小结:线段树 & 主席树 & 树状数组

    概要: 就是用来维护区间信息,然后各种秀智商游戏. 技巧及注意: 一定要注意标记的下放的顺序及影响!考虑是否有叠加或相互影响的可能! 和平衡树相同,在操作每一个节点时,必须保证祖先的tag已经完全下放 ...

随机推荐

  1. 从php到浏览器的缓存机制,不得不看!

    所有的php程序员都知道在php脚本里面执行 echo "1";访客的浏览器里面就会显示"1". 但是我们执行下面的代码的时候,并不是显示"1&quo ...

  2. Oracle BEQ方式连接配置

    Oracle BEQ方式连接配置 服务端和客户端在同一台机器上,可以使用BEQ连接,BEQ连接可以理解为进程间直接通信,不需要走网络监听,性能更高. 可以参考MOS:How To Connect Us ...

  3. 【原创】梵高油画用深度卷积神经网络迭代十万次是什么效果? A neural style of convolutional neural networks

    作为一个脱离了低级趣味的码农,春节假期闲来无事,决定做一些有意思的事情打发时间,碰巧看到这篇论文: A neural style of convolutional neural networks,译作 ...

  4. ubuntu14.04 下手动安装java jdk

    ubuntu14.04 下手动安装java jdk 第一步: 下载jdk.tar.gz (这里假设下载的文件名为jdk.tar.gz) 第二步: 解压 sudo tar -zxvf ./jdk.tar ...

  5. TimSort算法分析

    Timsort是一种混合稳定的排序算法,采用归并排序混合插入排序的设计,在多种真实数据上表现良好. 它基于一个简单的事实,实际中大部分数据都是部分有序(升序或降序)的. 它于2002年由Tim Pet ...

  6. C# Webform中读取Windows AD/LDAP域用户清单

    直接上干货,核心代码如下,读取出来相应的用户清单到DataTable中.需要其它字段可以自己增加,别忘了引用using System.DirectoryServices. #region privat ...

  7. C++编程练习(11)----“图的最短路径问题“(Dijkstra算法、Floyd算法)

    1.Dijkstra算法 求一个顶点到其它所有顶点的最短路径,是一种按路径长度递增的次序产生最短路径的算法. 算法思想: 按路径长度递增次序产生算法: 把顶点集合V分成两组: (1)S:已求出的顶点的 ...

  8. ASP.NET Core MVC 中设置全局异常处理方式

    在asp.net core mvc中,如果有未处理的异常发生后,会返回http500错误,对于最终用户来说,显然不是特别友好.那如何对于这些未处理的异常显示统一的错误提示页面呢? 在asp.net c ...

  9. shiro.ini 配置详解

    引用: [1]开涛的<跟我学shiro> [2]<SpringMVC整合Shiro> [3]<shiro简单配置> [4]Apache shiro集群实现 (一) ...

  10. Java语言跨平台原理

    Java语言有一个很重要的原理叫:跨平台性. 在介绍Java语言的跨平台性之前首先要介绍一个很重要的概念:JVM: JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一 ...