http://codeforces.com/problemset/problem/596/C

题目大意:  给你n个数对  确保如果(x,y)存在这个集合  那么  0<=x'<=x && 0<=y'<=y (x',y')也一定存在这个集合    他们规定 i的美观值=(y-x)   还会给你一个美观值序列   每一个如果都有唯一一个i与之匹配   并且 这个集合后面的所有数都不能小于前面的数  也就是说(

a[s[i]].x<=a[s[i-1]].x && a[s[i]].y<=a[s[i-1]].y

分析:   我觉得应该先对a数组从小到大排序  这样避免以后在比较的时候出现错误

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<queue>
#include<algorithm>
#include<iostream> using namespace std;
#define N 500050
const double ESP = 1e-;
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a)) int s[N]; struct node
{
int x,y;
}a[N];
struct Node
{
int v,k;
}b[N],c[N]; int cmp(Node p,Node q)
{
if(p.v!=q.v)
return p.v<q.v;
else
return p.k<q.k;
} int cmp1(node p,node q)
{
if(p.x!=q.x)
return p.x<q.x;
else
return p.y<q.y;
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(s,);
memset(a,);
memset(b,);
memset(c,);
for(int i=;i<n;i++)
{
scanf("%d %d",&a[i].x,&a[i].y);
}
sort(a,a+n,cmp1);
for(int i=;i<n;i++)
{
c[i].v=a[i].y-a[i].x;
c[i].k=i;
}
for(int i=;i<n;i++)
{
scanf("%d",&b[i].v);
b[i].k=i;
}
sort(b,b+n,cmp);
sort(c,c+n,cmp);
int flag=;
for(int i=;i<n;i++)
{
if(b[i].v!=c[i].v)
{
flag=;
break;
}
else
{
s[b[i].k]=c[i].k;
}
}
for(int i=;i<n;i++)
{
if(a[s[i]].x<=a[s[i-]].x && a[s[i]].y<=a[s[i-]].y)
flag=;
if(flag==)
break;
}
if(flag==)
printf("NO\n");
else
{
printf("YES\n");
for(int i=;i<n;i++)
{
printf("%d %d\n",a[s[i]].x,a[s[i]].y);
}
}
}
return ;
}

C. Wilbur and Points---cf596C的更多相关文章

  1. 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 ...

  2. 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/ ...

  3. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. CodeForces 596C Wilbur and Points

    先对n个点分类,然后按题意要求构造,构造的时候判断这个点的右上方之前是否有点,判断可以用线段树来操作. #include<cstdio> #include<cstring> # ...

  5. Codeforces Round #331 (Div. 2)

    水 A - Wilbur and Swimming Pool 自从打完北京区域赛,对矩形有种莫名的恐惧.. #include <bits/stdc++.h> using namespace ...

  6. Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)

    C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...

  7. 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 ...

  8. 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 ...

  9. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  10. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

随机推荐

  1. ssl证书过期问题解决

    1,ssl证书失效现象 小程序debug有如下证书无效信息: 浏览器访问https://ic-park.net:30001/indoornav/callFunction1.php 提示证书风险. 2, ...

  2. ssget使用方法

    语法: (ssget [sel-method] [pt1 [pt2]] [pt-list] [filter-list]) ssget 的参数均为可选参数,需要注意的是可选参数之间的组合条件.以下语法表 ...

  3. bzoj4951 [Wf2017]Money for Nothing

    题目描述 题解: 答案显然是$max((q-p)*(e-d))$ 依然先贪心. 对于工厂,我们倾向于$pi<pj,di<dj$的; 对于买家,我们倾向于$qi>qj,ei>ej ...

  4. Openjudge-4110-圣诞老人的礼物

    这一题是一道贪心的题目,但是它比较特殊的地方在于糖果可以分开拿,我们不必整箱拿,所以我们可以直接就把糖果按照价值比从大到小排序,然后整箱装不下的时候,剩余重量乘以它的价值比,这样就算出来了. 对于结构 ...

  5. 从多表连接后的select count(*)看待SQL优化

    从多表连接后的select count(*)看待SQL优化 一朋友问我,以下这SQL能直接改写成select count(*) from a吗? SELECT COUNT(*) FROM a LEFT ...

  6. Linux组和提权

    目 录 第1章 组命名管理**    1 1.1 group组信息和密码信息    1 1.1.1 /etc/group 组账户信息    1 1.1.2 /etc/gshadow 组密码信息     ...

  7. Java实现深拷贝和浅拷贝

    1.类实现Cloneable才可以进行对象拷贝 2.Cloneable只实现浅拷贝,需要实现深拷贝的必须要重写clone()方法 3.利用反序列化也可以实现深拷贝,但是反序列化耗时较长 n.浅拷贝是指 ...

  8. pytest以类形式的测试用例

    from __future__ import print_function#pytest以类形式的测试用例class TestClass: @classmethod def setup_class(c ...

  9. 有上下界的网络流 loj115 loj116 loj 117

    参考文章 无源汇有上下界的可行流 有源汇有上下界的最大流 有源汇有上下界的最小流 无源汇有上下界可行流 以 loj115 为例. 剥离出必要边与自由边. #include <iostream&g ...

  10. SQL server将某个字符串将按指定字符分解成子字符串(行转列)

    今天突然需要用到这样的方法,在网上找过很多,大体都写的很复杂,这个简单实用.转载自ChineseMoonGod的博客:https://www.cnblogs.com/ChineseMoonGod/p/ ...