• CF div2 331 C


    C. Wilbur and Points
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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 (xy) 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 (xy) 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 (xy) 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 test(s)
    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 is0, 1, 2. Therefore, the answer does not exist.

    一开始用了两个队列贪心搞,果断WA,还是菜的一笔啊,然后喵了一眼题解跟代码。。。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <stack>
     5 #include <queue>
     6 #include <map>
     7 #include <algorithm>
     8 #include <vector>
     9 #include <set>
    10 
    11 using namespace std;
    12 
    13 const int maxn = 1000005;
    14 
    15 const int inf = 999999;
    16 
    17 typedef long long LL;
    18 typedef pair<int,int> P;
    19 
    20 #define xx first
    21 #define yy second
    22 
    23 
    24 int a[maxn];
    25 int w[maxn];
    26 int c[maxn];
    27 
    28 struct node
    29 {
    30     int x,y;
    31 }b[maxn];
    32 
    33 map<int,set <P> > mp;
    34 vector<P>Q;
    35 
    36 
    37 
    38 int main()
    39 {
    40     int n;
    41     scanf("%d",&n);
    42     int x,y;
    43     for(int i=0;i<n;i++){
    44         scanf("%d%d",&x,&y);
    45         c[i] = y - x;
    46         mp[y-x].insert(P(x,y));
    47     }
    48     for(int i=0;i<n;i++){
    49         scanf("%d",&w[i]);
    50         a[i] = w[i];
    51     }
    52     sort(a,a+n);
    53     sort(c,c+n);
    54     int flag = 1;
    55     for(int i=0;i<n;i++){
    56         if(a[i]!=c[i]){
    57 
    58             puts("NO");
    59             return 0;
    60         }
    61     }
    62     for(int i=0;i<n;i++){
    63         set<P>::iterator it = mp[w[i]].begin();
    64         Q.push_back(*it);
    65         mp[w[i]].erase(it);
    66     }
    67     for(int i=1;i<n;i++){
    68         if(Q[i].xx<Q[i-1].xx&&Q[i].yy<=Q[i-1].yy){
    69             flag = 0;
    70             break;
    71         }
    72     }
    73     if(!flag) puts("NO");
    74     else {
    75        puts("YES");
    76        for(int i=0;i<n;i++){
    77         printf("%d %d
    ",Q[i].xx,Q[i].yy);
    78        }
    79     }
    80   return 0;
    81 }
    View Code
  • 相关阅读:
    转--Android中调用webservice的工具类
    转--Android实现ListView过滤功能,继承于BaseAdapter,非ArrayAdapter。
    Kubernetes 1.5 配置dns
    Kubernetes 1.5安装
    HAproxy健康检查的三种方式
    某电商网站线上drbd+heartbeat+nfs配置
    sonarqube代码检测
    Sersync实时同步
    RabbitMQ配置文件
    SVNManager配置
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4979578.html
Copyright © 2020-2023  润新知