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

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

题意

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

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

问你能否找到

题解:

巧妙地利用STL

代码

#include 

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


你可能感兴趣的:(STL)