巧妙地利用STL map set pair 贪心+排序 Codeforces Round #331 (Div. 2)C. Wilbur and Points

来源:互联网 发布:变革管理 知乎 编辑:程序博客网 时间:2024/06/06 00:07

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

题意

给你一堆点,要求你找到一个集合,使得他的y[i]-x[i]=w[i]

且如果xj>=xi && yj>=yi,那么id[i]>id[j]

问你能否找到

题解:

巧妙地利用STL

代码

#include <bits/stdc++.h>using namespace std;const int N = 200010;int main(){#ifndef ONLINE_JUDGE    freopen("in.txt", "r", stdin);#endif    ios_base::sync_with_stdio(0);    cin.tie(0);    int n;    scanf("%d", &n);    map < int, set < pair <int, int> > > mp;    for (int i = 0; i < n; i++)    {        int x, y;        scanf("%d %d", &x, &y);        mp[y - x].insert(make_pair(x, y));    }    vector < pair <int, int> > p(n);    for (int i = 0; i < n; i++)    {        int diff;        scanf("%d", &diff);        if (mp[diff].empty())        {            puts("NO");            return 0;        }        p[i] = *(mp[diff].begin());        mp[diff].erase(mp[diff].begin());    }    for (int i = 1; i < n; i++)    {        int x = p[i].first;        int y = p[i].second;        int prex = p[i-1].first;        int prey = p[i-1].second;        if ((x<prex&&y<=prey)||(x<=prex&&y<prey))        {            puts("NO");            return 0;        }    }    puts("YES");    for (int i = 0; i < n; i++)    {        int x = p[i].first;        int y = p[i].second;        printf("%d %d\n", x, y);    }    return 0;}


0 0