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/problem/C
Description
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.
Sample Input
5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0
Sample Output
YES
0 0
1 0
2 0
0 1
1 1
HINT
题意
给你一堆点,要求你找到一个集合,使得他的y[i]-x[i]=w[i]
且如果xj>=xi && yj>=yi,那么id[i]>id[j]
问你能否找到
题解:
我们贪心取最小就好了,然后再check一下就好了
check可以使用线段树,也可以先按照Y排序,然后再按照X排序,再扫一遍来check
代码
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
using namespace std; struct node
{
int x,y,z;
int id;
};
node p[];
bool cmp(node a,node b)
{
if(a.x==b.x&&a.y==b.y)return a.id<b.id;
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
int b[];
map<int,int> H;
vector<int> X;
vector<int> Y;
int tot = ;
vector<node> Q[];
int add[];
vector<node> Q2[];
int main()
{
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].z = p[i].y-p[i].x;
if(H[p[i].z]==)
H[p[i].z]=tot++;
Q[H[p[i].z]].push_back(p[i]);
} for(int i=;i<tot;i++)
sort(Q[i].begin(),Q[i].end(),cmp);
for(int i=;i<=n;i++)
{
scanf("%d",&b[i]);
if(H[b[i]]==)
return puts("NO");
int t = H[b[i]];
if(add[t]==Q[t].size())return puts("NO");
X.push_back(Q[t][add[t]].x);
Y.push_back(Q[t][add[t]].y);
add[t]++;
}
for(int i=;i<n;i++)
{
node kkk;
kkk.x = X[i],kkk.y = Y[i];
kkk.id = i;
Q2[kkk.y].push_back(kkk);
} for(int i=;i<=;i++)
sort(Q2[i].begin(),Q2[i].end(),cmp);
for(int i=;i<=;i++)
{
if(Q2[i].size()<=)continue;
for(int j=;j<Q2[i].size()-;j++)
{
if(Q2[i][j].id>Q2[i][j+].id)
return puts("NO");
}
}
puts("YES");
for(int i=;i<X.size();i++)
{
printf("%d %d\n",X[i],Y[i]);
}
}
Codeforces Round #331 (Div. 2)C. Wilbur and Points 贪心的更多相关文章
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
C. Wilbur and Points time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 #297 (Div. 2)C. Ilya and Sticks 贪心
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #331 (Div. 2)
水 A - Wilbur and Swimming Pool 自从打完北京区域赛,对矩形有种莫名的恐惧.. #include <bits/stdc++.h> using namespace ...
随机推荐
- 《C++ Primer 4th》读书笔记 第12章-类
原创文章,转载请注明出处:http://www.cnblogs.com/DayByDay/p/3936473.html
- 在Android应用中使用Clean架构
自从开始开发安卓应用,我一直感觉我可以做得更好.我看过不少烂代码,其中当然有我写的.安卓系统的复杂性加上烂代码势必酿成灾祸,所以从错误中成长就很重要.我Google了如何更好地开发应用,发现了这个叫做 ...
- CSS HACK区别IE6、IE7、IE8、Firefox兼容性
相信不少人,都特别清楚CSS HACK,而其中也是区别IE6.IE7.IE8.Firefox兼容性问题用的,CSS hack由于不同的浏览器,对CSS的解析认识不一样,因此会导致生成的页面效果不一样. ...
- solr4.5配置中文分词器mmseg4j
solr4.x虽然提供了分词器,但不太适合对中文的分词,给大家推荐一个中文分词器mmseg4j mmseg4j的下载地址:https://code.google.com/p/mmseg4j/ 通过以下 ...
- Oracle EM 不能访问
zwt2001267 原文 Oracle EM 不能访问 1. cmd控制启动EM: C:\Users\Administrator>emctl start dbconsoleEnvironmen ...
- HDU5045-Contest(状压dp)
题意: 有n个学生,m道题,给出每个同学解出m个问题的概率,在解题过程中每个学生的解题数的差不大于1,求最大能解出题目数的期望 分析: n很小,知道用状压,但是比赛没做出来(脑子太死了,有一个限制条件 ...
- [OFBiz]开发 二
1.svn中check出的apache-ofbiz-10.04(svn_2010-04-01代码备分)由于它的所有文件都不含有中文,所以Eclipse使用什么编码方式都可以(ISO, GBK, UTF ...
- bzoj 3505 [Cqoi2014]数三角形(组合计数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题意] 在n个格子中任选3点构成三角形的方案数. [思路] 任选3点-3点共线 ...
- HDU 1536 sg-NIM博弈类
题意:每次可以选择n种操作,玩m次,问谁必胜.c堆,每堆数量告诉. 题意:sg—NIM系列博弈模板题 把每堆看成一个点,求该点的sg值,异或每堆sg值. 将多维转化成一维,性质与原始NIM博弈一样. ...
- 限制波尔兹曼机(Restricted Boltzmann Machines)
能量模型的概念从统计力学中得来,它描述着整个系统的某种状态,系统越有序,系统能量波动越小,趋近于平衡状态,系统越无序,能量波动越大.例如:一个孤立的物体,其内部各处的温度不尽相同,那么热就从温度较高的 ...