zoukankan      html  css  js  c++  java
  • Codeforces Round #283 (Div. 2) E. Distributing Parts 贪心+set二分

    E. Distributing Parts
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are an assistant director in a new musical play. The play consists of n musical parts, each part must be performed by exactly one actor. After the casting the director chose m actors who can take part in the play. Your task is to assign the parts to actors. However, there are several limitations.

    First, each actor has a certain voice range and there are some parts that he cannot sing. Formally, there are two integers for each actor,ci and di (ci ≤ di) — the pitch of the lowest and the highest note that the actor can sing. There also are two integers for each part — ajand bj (aj ≤ bj) — the pitch of the lowest and the highest notes that are present in the part. The i-th actor can perform the j-th part if and only if ci ≤ aj ≤ bj ≤ di, i.e. each note of the part is in the actor's voice range.

    According to the contract, the i-th actor can perform at most ki parts. Besides, you are allowed not to give any part to some actors (then they take part in crowd scenes).

    The rehearsal starts in two hours and you need to do the assignment quickly!

    Input

    The first line contains a single integer n — the number of parts in the play (1 ≤ n ≤ 105).

    Next n lines contain two space-separated integers each, aj and bj — the range of notes for the j-th part (1 ≤ aj ≤ bj ≤ 109).

    The next line contains a single integer m — the number of actors (1 ≤ m ≤ 105).

    Next m lines contain three space-separated integers each, cidi and ki — the range of the i-th actor and the number of parts that he can perform (1 ≤ ci ≤ di ≤ 109, 1 ≤ ki ≤ 109).

    Output

    If there is an assignment that meets all the criteria aboce, print a single word "YES" (without the quotes) in the first line.

    In the next line print n space-separated integers. The i-th integer should be the number of the actor who should perform the i-th part. If there are multiple correct assignments, print any of them.

    If there is no correct assignment, print a single word "NO" (without the quotes).

    Examples
    input
    3
    1 3
    2 4
    3 5
    2
    1 4 2
    2 5 1
    output
    YES
    1 1 2
    input
    3
    1 3
    2 4
    3 5
    2
    1 3 2
    2 5 1
    output
    NO

     题意:给你n首歌,m个歌手,每首歌和歌手都有最低音和最高音,只有歌手的最低音小于等于歌的最低音并且最高音大于等于歌的最高音才能唱这首歌,问是否能唱完,求唱完后的序列;

    思路:排序,插入最低音在这之前的歌手,找到最低 满足的歌手;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    const int N=1e5+10,M=1e6+10,inf=1e9+10,mod=1e9+7;
    struct iterval
    {
        int l,r,pos;
        bool operator <(const iterval &b)const
        {
            if(l!=b.l)
            return l<b.l;
            return r<b.r;
        }
    }a[N];
    struct is
    {
        int a,b,k,pos;
        bool operator <(const is &x)const
        {
            if(a!=x.a)
            return a<x.a;
            return b<x.b;
        }
    }b[N];
    set< pair < pair < int , int > , int>  >s;
    set< pair < pair < int , int > , int>  >::iterator it,itt;
    int ans[N];
    int main()
    {
        int n,m;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d%d",&a[i].l,&a[i].r),a[i].pos=i;
            sort(a,a+n);
        scanf("%d",&m);
        for(int i=0;i<m;i++)
            scanf("%d%d%d",&b[i].a,&b[i].b,&b[i].k),b[i].pos=i;
            sort(b,b+m);
        int flag=0,gg=0;
        for(int i=0;i<n;i++)
        {
            while(b[flag].a<=a[i].l&&flag<m)
            {
                s.insert(make_pair(make_pair(b[flag].b,b[flag].k),b[flag].pos));
                flag++;
            }
            it=s.lower_bound(make_pair(make_pair(a[i].r,0),0));
            if(it==s.end())
            {
                gg=1;
                break;
            }
            ans[a[i].pos]=it->second;
            pair < pair < int , int > , int> k=*it;
            s.erase(it);
            if(k.first.second>1)
            {
                k.first.second--;
                s.insert(k);
            }
        }
        if(gg)
        {
            printf("NO
    ");
        }
        else
        {
            printf("YES
    ");
            for(int i=0;i<n;i++)
            printf("%d ",ans[i]+1);
        }
        return 0;
    }
  • 相关阅读:
    数据库查询服务DBCacheServer
    SmallMQ实现发布
    数据库查询服务DBCacheServer
    Mysql ACID与隔离级别
    jsp拾遗
    Git项目创建与提交
    Spring Boot详细学习地址转载
    Spring Cloud微服务体系搭建
    前后端分离项目启动参考
    JVM类加载机制总结
  • 原文地址:https://www.cnblogs.com/jhz033/p/5924940.html
Copyright © 2011-2022 走看看