【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种字符中的一个; ...
随机推荐
- Linux 从core信息中找到TLS信息
背景 我们在查core问题时,有时候须要查看某个TLS变量的值.可是GDB没有提供直接的命令,或者我不知道.这篇文字的目的.就是想办法从core文件里找出某个线程存放TLS变量的内容. 依据 Linu ...
- redis 模糊删除实现
redis 没有直接提供模糊删除的实现,我们可以根据现有的指令进行组合实现: import java.util.Arrays; import java.util.Set; import javax.a ...
- 微信支付v2开发(6) 发货通知
本文介绍微信支付中发货通知功能的实现. 一.发货通知 为了更好地跟踪订单的情况,需要第三方在收到最终支付通知之后,调用发货通知API告知微信后台该订单的发货状态. 发货时间限制:虚拟.服务类24小时内 ...
- springboot 使用FreeMarker模板(转)
在spring boot中使用FreeMarker模板非常简单方便,只需要简单几步就行: 1.引入依赖: <dependency> <groupId>org.springfra ...
- 读<阿里亿级日活网关通道架构演进>有感
读<阿里亿级日活网关通道架构演进>时对优化方法有些概念不理解,特意搜索了一下,拓展自己的思路. 其中的优化: 优化方法中1,2比较常见,3,4我知道的比较少,很感兴趣.就继续追踪下去: 于 ...
- linux安装anaconda
打开网址:https://repo.continuum.io/archive/ 下载对应版本: 然后把下载的文件放到linux系统上 在终端执行: bash Anaconda3-5.1.0-Linux ...
- nginx启用https访问
什么是https? https 全称:Hyper Text Transfer Protocol over Secure Socket Layer,是http的安全版.即http下加入SSL协议层,因此 ...
- UVA 10917 Walk Through the Forest SPFA
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...
- (转)把Sublime Text 2 加入右键菜单(带图标),Edit with Sublime Text
转自 http://www.turen.me/archives/509 Sublime Text 2 是现在很受大家欢迎的编辑器了,不仅是在web前端,在书定简单的php.Js等代码时,也是相当的好用 ...
- [AngularFire 2 ] Hello World - How To Write your First Query using AngularFire 2 List Observables ?
In this lesson we are going to use AngularFire 2 for the first time. We are going to configure the A ...