Problem I. Improvements
2015-10-27 19:07
369 查看
题目描述:
Problem I. ImprovementsInput file: improvements.in
Output file: improvements.out
Son Halo owns n spaceships numbered from 1 to n and a space station. They are initially placed on one
line with the space station so the spaceship i is positioned xi meters from the station and all ships are
on the same side from the station (xi > 0). All xi are distinct. Station is considered to have number 0
and x0 is considered to be equal to 0.
Every two spaceships with consequent numbers are connected by a rope, and the first one is connected
to the station. The rope number i (for 1 ≤ i ≤ n) connects ships i and i−1. Note, that the rope number
1 connects the first ship to the station.
Son Halo considers that the rope i and the rope j intersect when the segments [x
min
i
, xmax
i
] and
[x
min
j
, xmax
j
] have common internal point but neither one of them is completely contained in the other,
where x
min
k = min(xk−1, xk), x
max
k = max(xk−1, xk). That is:
[
x
min
i < xmin
j & x
min
j < xmax
i & x
max
i < xmax
j
x
min
j < xmin
i & x
min
i < xmax
j & x
max
j < xmax
i
Son Halo wants to rearrange spaceships in such a way, that there are no rope intersections. Because he
is lazy, he wants to rearrange the ships in such a way, that the total number of ships that remain at their
original position xi
is maximal. All the ships must stay on the same side of the station and at different
positions xi after rearrangement. However, ships can occupy any real positions xi after rearrangement.
Your task is to figure out what is the maximal number of ships that can remain at their initial positions.
Input
The first line of the input file contains n (1 ≤ n ≤ 200 000) — the number of ships. The following line
contains n distinct integers xi (1 ≤ xi ≤ n) — the initial positions of the spaceships.
Output
The output file must contain one integer — the maximal number of ships that can remain at their initial
positions in the solution of this problem.
Sample input and output
improvements.in improvements.out
4
1 3 2 4
3
4
1 4 2 3
4
Note
In the first sample Son Halo can move the second spaceship in the position between the first and the
third to solve the problem while keeping 3 other ships at their initial positions.
In the second sample there are no rope intersections, so all 4 ships can be left at their initial positions.
题解:
当时死活想不出来怎么做.多总结点.最关键的是,想合法的情况张什么样子.而不是一直去想贪心的调整.因为我们能猜到大概会借助最长上升子序列来解决最终问题,我们应该只关注满足条件的形态. 其中一种想法是,看i-1 和 i 之间能够有什么. 如果出现了一个比i-1小的数,那么数k要求k-1一定在中间,一直产生连锁,会发现0也需要,就推出矛盾. 而i-1 和 i之间有大于i的是可以的. 也可以打标来观察规律,实在是很重要的一种方法.
最终推出来合法答案是:前一段单调上升,后一段单调下降.
重点:
想到用lis的时候,我们不关注怎么调整,关注最终结果的规律.看给出的稀奇古怪的条件会约束成一个什么样的结果 打标来看 或者枚举两个元素来看都是很好的方法.
代码:
//代码没有写= =
相关文章推荐
- 023 Merge k Sorted Lists [Leetcode]
- CoreData的使用之二
- Objective-C总Runtime的那点事儿(一)消息机制
- libev / libuv / python tornado / nginx 性能比较
- hihocodxer1187 Divisors
- Activity进阶知识整理
- opencv 实现导向滤波
- IIS7.5应用程序池集成模式和经典模式的区别【转】
- UVa10047 The Monocycle
- BZOJ1083繁忙的都市
- 《windows程序设计》选择文件
- Android自定义ListView
- [DEEP LEARNING An MIT Press book in preparation]Deep Learning for AI
- android 实现button单击双击事件同时监控
- 求数组的子数组之和的最大值
- 软体project(四)——一生
- 基础数论模版
- Win32 API 选择文件和文件夹
- python 学习笔记(02)
- JavaScript—————DOM