Codeforces596C. Wilbur and Points
来源:互联网 发布:js中树形菜单制作方法 编辑:程序博客网 时间:2024/05/21 09:42
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x,y) belongs to the set, then all points (x',y'), such that0 ≤ x' ≤ x and0 ≤ y' ≤ y also belong to this set.
Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from1 ton. In order to make the numberingaesthetically pleasing, Wilbur imposes the condition that if some point (x,y) gets number i, then all (x',y') from the set, such thatx' ≥ x andy' ≥ y must be assigned a number not less thani. For example, for a set of four points (0,0), (0,1), (1, 0) and (1,1), there are two aesthetically pleasing numberings. One is1,2, 3, 4 and another one is 1, 3, 2, 4.
Wilbur's friend comes along and challenges Wilbur. For any point he defines it'sspecial value ass(x, y) = y - x. Now he gives Wilbur somew1,w2,...,wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets numberi has it's special value equal towi, that iss(xi, yi) = yi - xi = wi.
Now Wilbur asks you to help him with this challenge.
The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.
Next follow n lines with points descriptions. Each line contains two integersx andy (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x,y) is present in the input, then all points (x',y'), such that0 ≤ x' ≤ x and0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. Thei-th of them iswi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.
If there exists an aesthetically pleasant numbering of points in the set, such thats(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".
If a solution exists, proceed output with n lines. On thei-th of these lines print the point of the set that gets numberi. If there are multiple solutions, print any of them.
52 00 01 01 10 10 -1 -2 1 0
YES0 01 02 00 11 1
31 00 02 00 1 2
NO
In the first sample, point (2, 0) gets number 3, point (0,0) gets number one, point (1,0) gets number2, point (1,1) gets number5 and point (0,1) gets number4. One can easily check that this numbering is aesthetically pleasing andyi - xi = wi.
In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is0,1, 2. Therefore, the answer does not exist.
题意:给出N个点,有给出N个价值,点i的价值为yi-xi,每个点给一个标记值1~N,当已知xi,yi的标记值为i,那么当又一个点的x和分别大于等于xi,yi时,这个点的标记值不能小于i。问存不存在排列能凑出给出的N个价值。
思路:老实说我不太清楚题意,WA了两发后根据错的数据修改一下排序过了。我是先把已知的点按他们的价值升序排,若价值相等就按y升序排,若y也相等就按x升序排。
给出的N个价值按升序排,价值相等按序号升序排。排完后一 一 对比,若出现不点的价值不同于对应数据给的价值则no,对比后再遍历一边点,若出现xi,yi均小于xi-1,yi-1的话no,
最后就可以再排序将结果输出了。
- Codeforces596C. Wilbur and Points
- Codeforces596C Wilbur and Points(贪心)
- 596 C. Wilbur and Points
- cf C. Wilbur and Points (STL_vector)
- Codeforces 596 C Wilbur and Points
- 续 Codeforces 596 C Wilbur and Points
- 续续 Codeforces 596 C Wilbur and Points
- [堆+贪心] CF596C. Wilbur and Points
- Codeforces 596 C Wilbur and Points【贪心】
- 【26.67%】【codeforces 596C】Wilbur and Points
- C. Wilbur and Points(简单贪心加合法性判断)
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
- Codeforces 596C Wilbur and Points 【贪心 + sort】
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
- codeforces#331-C - Wilbur and Points-set/贪心乱搞
- Codeforces Round #331 (Div. 2)-C. Wilbur and Points
- Codeforces Round #331 (Div. 2)C. Wilbur and Points(模拟+STL)
- mvp(一)
- 62. Unique Paths
- Maven学习总结(八)——使用Maven构建多模块项目
- Java基础之-压缩与解压
- 反射类的普通方法
- Codeforces596C. Wilbur and Points
- java中线程池的几种实现方式
- BNU 1642 简单的图论问题? 最短路+BFS
- 【PHP】函数explode和split的区别
- 一道C语言笔试题解析,检查源代码中的错误
- 反射类的属性
- Java方法的学习
- mvp(二)
- 使用moveTaskToback()让APP退到后台