【26.67%】【codeforces 596C】Wilbur and Points
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Input
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.
Output
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.
Examples
input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
output
YES
0 0
1 0
2 0
0 1
1 1
input
3
1 0
0 0
2 0
0 1 2
output
NO
Note
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.
【题目链接】:http://codeforces.com/contest/596/problem/C
【题解】
题中所给的y-x这个特殊值;其实就是如上,约束这些点在y-x=wi这条线上;
而题中所给的条件转换一下可以理解为;
对于任意(x,y);如果x’<=x && y’<=y;则(x’,y’)的序号要在(x,y)这个点之前;
最后所给的要求序列;
相当于我们要在y-x=wi这条线段上选一个点放在序列的相应位置;
那我们要怎么选呢?
肯定要从上图上的这些圆圈圈中的点开始选(即从线的左下角开始往右上角依次选);
现在假设我们选过的点都标为红色;
然后w=1;
则我们要选如下这个点
那我们能选这个这个点吗?
答案是不行;
因为在这个蓝点的正下方有一个点(1,1)还没被选;
如果我们先选了那个蓝点;必然下面这个点会在这个蓝点的序号之后(所有的点都会出现,所以下面那个点是肯定会在后面选的);
但是下面那个点的横坐标1<=1,且纵坐标1<=2;这个点是肯定要在这个蓝点之前被选的;【还记的我们转换成的条件吗:对于任意(x,y);如果x’<=x && y’<=y;则(x’,y’)的序号要在(x,y)这个点之前;】
这就说明序列不合法;
因为我们是按照直线从左下往右上选的;而且每次都只选一个点;所以我们可以在选一个点(x,y)的时候先判断(x-1,y)和(x,y-1)有没有被选(边界就不用判断了);如果其中有一个点没被选;则不满足条件;
(我们可以在遇到w的时候,看看y-x=w这条线上从左下到右上的第一个没被选的点是啥(记录这条线上被选过的点的最右上那个点的横坐标即可),然后判断一下x-1,y和y,x-1有没有被加入balabalba一下就可以过了);
【完整代码】
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
//const int MAXN = x;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);
map <int,int> dic;
map <int,int> maxx;
map <pair <int,int>,int> pre;
int n;
vector <pair <int,int> > ans;
void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
for (int i = 1;i <= n;i++)
{
int x,y;
rei(x);rei(y);
int temp = y-x;
dic[temp]++;
}
for (int i =-100000;i <= 0;i++)
maxx[i] = -i;
for (int i = 1;i <= n;i++)
{
int t;
rei(t);
int x,y;
x = maxx[t];y = x+t;
ans.push_back(make_pair(x,y));
if (x-1>=0 && !pre[make_pair(x-1,y)])
{
puts("NO");
return 0;
}
if (y-1>=0 && !pre[make_pair(x,y-1)])
{
puts("NO");
return 0;
}
pre[make_pair(x,y)] = 1;
dic[t]--;
maxx[t]++;
}
for (int i = -100000;i <= 100000;i++)
if (dic[i]!=0)
{
puts("NO");
return 0;
}
puts("YES");
for (int i = 0;i <= n-1;i++)
printf("%d %d\n",ans[i].first,ans[i].second);
return 0;
}
【26.67%】【codeforces 596C】Wilbur and Points的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【26.83%】【Codeforces Round #380C】Road to Cinema
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【26.09%】【codeforces 579C】A Problem about Polyline
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【23.26%】【codeforces 747D】Winter Is Coming
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 797C】Minimal string
[题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...
- 【codeforces 510C】Fox And Names
[题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...
- 【codeforces 807B】T-Shirt Hunt
[题目链接]:http://codeforces.com/contest/807/problem/B [题意] 你在另外一场已经结束的比赛中有一个排名p; 然后你现在在进行另外一场比赛 然后你当前有一 ...
- 【codeforces 67A】Partial Teacher
[题目链接]:http://codeforces.com/problemset/problem/67/A [题意] 给一个长度为n-1的字符串; 每个字符串是'L','R','='这3种字符中的一个; ...
随机推荐
- 【算法导论-36】并查集(Disjoint Set)具体解释
WiKi Disjoint是"不相交"的意思.Disjoint Set高效地支持集合的合并(Union)和集合内元素的查找(Find)两种操作,所以Disjoint Set中文翻译 ...
- Javascript和jquery事件--点击事件和触发超链接
前面的不过是一些基础的知识,真正的一些事件还是有点不同.还有一些命名空间的问题.不过现在ie也开始接受W3C标准,而且平时开发也很少考虑ie了,一些事件就不考虑ie了. 点击事件--click 大部分 ...
- POJ 1466 Girls and Boys (ZOJ 1137 )最大独立点集
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=137 http://poj.org/problem?id=1466 题目大意: ...
- (转) 通过UUID在vSphere虚拟机内外识别硬盘
转自:http://ju.outofmemory.cn/entry/28398 简单介绍下应用场景:开发基于虚拟化IaaS的一些应用就免不了要跟虚拟机(VM)打交道,因为VM逻辑上独立于宿主机(hos ...
- Storm新特性之Flux
Storm新特性之Flux Flux是Storm版本号0.10.0中的新组件,主要目的是为了方便拓扑的开发与部署.原先在开发Storm拓扑的时候整个拓扑的结构都是硬编码写在代码中的,当要对其进行改动时 ...
- Xvisor ARM32 启动分析
Linux内核历史悠久,特性丰富,但是代码量庞大,各个子系统交叉繁琐.对于想要将操作系统内核各个特性研究一遍的人,有时候也只好"望Linux兴叹".Xvisor是一个较新的Type ...
- OpenExeConfiguration的使用
//应用程序的路径 string appPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App.exe"); ...
- 6 、字符编码笔记:ASCII,Unicode和UTF-8
1. ASCII码 我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两种状态,因此八个二进制位就可以组合出 256种状态,这被称为一个字节(byte) ...
- error C2220: warning treated as error - no 'object' file generated warning C4819: The file contains a character that cannot be represented in the current code page (936).
用Visual Studio2015 编译时,遇到如下编译错误: error C2220: warning treated as error - no 'object' file generated ...
- 使用C#版本的gdal库打开hdf文件
作者:朱金灿 来源:http://blog.csdn.net/clever101 最近应同事的请求帮忙研究下使用C#版的gdal库读取hdf文件,今天算是有一点成果,特地做一些记录. 首先是编译C#版 ...