Codeforces Round #331 (Div. 2) C. Wilbur and Points
2 seconds
256 megabytes
standard input
standard output
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 that 0 ≤ x' ≤ x and 0 ≤ 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 from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 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's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(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 integers x and y (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 that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.
The last line of the input contains n integers. The i-th of them is wi ( - 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 that s(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 the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
YES
0 0
1 0
2 0
0 1
1 1
3
1 0
0 0
2 0
0 1 2
NO
In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - 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 is 0, 1, 2. Therefore, the answer does not exist.
昏了头,做的时候想太多了.
先把a[i].y-a[i].x的数存进一个vector然后对于每个D[I],依次判断。
比如:对于D[I],如果V[D[I]].size==0那么输出”NO“;
V[D[I]]内部是按照先x,y排序的。
最后再判断一遍是否合法;
#include<bits/stdc++.h> using namespace std;
typedef long long ll; #define N 211111 struct node
{
int x,y,id;
node(int _x=,int _y=,int _z=)
{
x=_x;
y=_y;
id=_z;
}
}a[N];
int d[N],ans[N];
vector<node>b[N+N]; int cmp(node a,node b)
{
// min(a.x,a.y)<min(b.x,b.y);
if (a.x==b.x) return a.y<b.y;
return a.x<b.x;
} int main()
{
int n;
cin>>n;
for (int i=;i<=n;i++)
{
cin>>a[i].x>>a[i].y;
b[a[i].y-a[i].x+N].push_back(node(a[i].x,a[i].y,i));//要先+N,因为可能为负数
} for (int i=;i<=n;i++)
{
cin>>d[i];
d[i]+=N; if (b[d[i]].size()==)
{
cout<<"NO";
return ;
}
sort(b[d[i]].begin(),b[d[i]].end(),cmp);//每次都排序 是有点费时间
ans[i]=(*b[d[i]].begin()).id;
b[d[i]].erase(b[d[i]].begin());
} for (int i=;i<n;i++)
if (a[ans[i+]].x<=a[ans[i]].x&&a[ans[i+]].y<=a[ans[i]].y)//这里必须是<=,可能需要想想
{
cout<<"NO";
return ;
} cout<<"YES"<<endl;
for (int i=;i<=n;i++)
cout<<a[ans[i]].x<<" "<<a[ans[i]].y<<endl;
return ;
}
Codeforces Round #331 (Div. 2) C. Wilbur and Points的更多相关文章
- Codeforces Round #331 (Div. 2)C. Wilbur and Points 贪心
C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...
- Codeforces Round #331 (Div. 2) E. Wilbur and Strings dfs乱搞
E. Wilbur and Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596 ...
- Codeforces Round #331 (Div. 2) D. Wilbur and Trees 记忆化搜索
D. Wilbur and Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...
- Codeforces Round #331 (Div. 2) B. Wilbur and Array 水题
B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...
- Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题
A. Wilbur and Swimming Pool Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...
- Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #331 (Div. 2) B. Wilbur and Array
B. Wilbur and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #331 (Div. 2)
水 A - Wilbur and Swimming Pool 自从打完北京区域赛,对矩形有种莫名的恐惧.. #include <bits/stdc++.h> using namespace ...
- Codeforces Round #331 (Div. 2) A
A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...
随机推荐
- GSS5 spoj 2916. Can you answer these queries V 线段树
gss5 Can you answer these queries V 给出数列a1...an,询问时给出: Query(x1,y1,x2,y2) = Max { A[i]+A[i+1]+...+A[ ...
- HTML5移动开发中的meta与link
meta HTML5移动开发中的一些webkit专属头部标签,能够帮助浏览器更好的解析HTML代码,从而为HTML5移动开发提供更好的前端表现与体验 viewport网页缩放 1 <meta n ...
- 201509020-js
JS 关于(function( window, undefined ) {})(window)写法的理解 JS 关于(function( window, undefined ) {})(windo ...
- iframe滚动条的一些方法
用iframe布局,会碰到浏览器右边出现2个滚动条,简单代码解决用iframe布局,会碰到浏览器右边出现2个滚动条, 简单代码解决,用下面的代码可以把浏览器本身的滚动条去掉,只留页面产生的滚动条: b ...
- 快速调试chromium
上一篇我们简单的将了在Ubuntu上编译chromium,android content_shell_apk的编译,一切顺利的就能生成apk.但是我们仅仅只是照搬了人家google开源的东西,作为一个 ...
- (转)分布式缓存GemFire架构介绍
1什么是GemFire GemFire是一个位于应用集群和后端数据源之间的高性能.分布式的操作数据(operational data)管理基础架构.它提供了低延迟.高吞吐量的数据共享和事件分发.Gem ...
- [Bootstrap]组件(一)
Glyphicons字体图标 基类.glyphicon {position/top/display/font-family/} 具体类 {content} --表现在伪元素上 使用要点:a.基类 ...
- 洛谷 P3399 丝绸之路
题目背景 张骞于公元前138年曾历尽艰险出使过西域.加强了汉朝与西域各国的友好往来.从那以后,一队队骆驼商队在这漫长的商贸大道上行进,他们越过崇山峻岭,将中国的先进技术带向中亚.西亚和欧洲,将那里的香 ...
- 转帖:使用TortoiseGit处理代码冲突
原址:http://www.cnblogs.com/jason-beijing/p/5718190.html 场景一 user0 有新提交 user1 没有pull -> 写新代码 -&g ...
- VC按钮控件实现指示灯效果
VC为按钮控件添加图片的方法有很多种: 直接调用SetBitmap: CButton pButton->SetBitmap(hBitmap); 使用CButtonST控件: 使用CDC: 使用 ...