Distributing Parts CodeForces
来源:互联网 发布:淘宝代购衣服专柜真假 编辑:程序博客网 时间:2024/06/10 22:38
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 chosem 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 anddi (ci ≤ di) — the pitch of the lowest and the highest note that the actor can sing. There also are two integers for each part — aj and bj (aj ≤ bj) — the pitch of the lowest and the highest notes that are present in the part. The i-th actor can perform thej-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 mostki 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!
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 andbj — the range of notes for thej-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,ci,di andki — the range of thei-th actor and the number of parts that he can perform (1 ≤ ci ≤ di ≤ 109,1 ≤ ki ≤ 109).
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. Thei-th integer should be the number of the actor who should perform thei-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).
31 32 43 521 4 22 5 1
YES1 1 2
31 32 43 521 3 22 5 1
NO
题意:这里有一些歌剧和演员,每个演员有一个声域L,R,并且这个演员只可以出演k个歌剧,每个歌剧也需要一个声域至少覆盖L,R的演员才能出演,现在要求每个歌剧都要有一个演员去演请问该怎么分配,
第一眼看上去,我擦,网络流,二分图最大匹配,一看数据范围,发现不对了.......仔细想了想,是个贪心
思路如下:首先让歌剧和演员都按照他们的音域的R来排序,然后逐个考虑演员,把所有R小于当前考虑的演员的音域都加入set里面,然后找到L最接近演员L的,并让这个演员出演这个歌剧,如果找不到,就考虑下一个演员
代码如下:
#include <bits/stdc++.h>using namespace std;const int maxn = 1000005;struct node{ int l,r,pos,k;};node part[maxn],actor[maxn];bool cmp(node a,node b){ return a.r<b.r;}int ans[maxn];set<pair<int,int> >s;int main(){ s.clear(); memset(ans,0,sizeof(ans)); int n,m; cin>>n; for(int i=1;i<=n;i++){ scanf("%d%d",&part[i].l,&part[i].r); part[i].pos=i; } cin>>m; for(int i=1;i<=m;i++){ scanf("%d%d%d",&actor[i].l,&actor[i].r,&actor[i].k); actor[i].pos=i; } sort(part+1,part+1+n,cmp); sort(actor+1,actor+1+m,cmp); int i=1,j=1,ok=0; while(j<=m){ if(i<=n && part[i].r<=actor[j].r){ s.insert(make_pair(part[i].l,part[i].pos)); i++; } else{ set<pair<int,int> >::iterator it; it=s.lower_bound(make_pair(actor[j].l,0)); if(it==s.end()){ if(j==m && s.size()>0){//如果s不为空,并且最后一个演员没有歌剧演说明扔到s里面的某些歌剧没人演 ok=1; break; } else{ j++; continue; } } ans[it->second]=actor[j].pos; s.erase(it); actor[j].k--; if(actor[j].k==0)j++;//只有当这个演员不能再用的时候再考虑下一个演员 } } for(int i=1;i<=n;i++)if(ans[i]==0)ok=1; if(!ok){ cout<<"YES"<<endl; cout<<ans[1]; for(int i=2;i<=n;i++)printf(" %d",ans[i]); cout<<endl; } else{ cout<<"NO"<<endl; }}
- Distributing Parts CodeForces
- Codeforces 497C Distributing Parts
- codeforces 496 e Distributing Parts
- CODEFORCES, 496E Distributing Parts
- Codeforces 497C Distributing Parts set+贪心
- codeforces 496e Distributing Parts 贪心
- Codeforces 496E - Distributing Parts 贪心
- codeforces 496E Distributing Parts(贪心)
- Codeforces 496E. Distributing Parts 排序+贪心
- Codeforces 496E Distributing Parts(贪心)
- CF - 496E Distributing Parts - 离线
- CF 496E(Distributing Parts-序列混合贪心+set)
- Code Forces 496 E. Distributing Parts(贪心)
- Distributing to Specific Screens
- Distributing Ballot Boxes
- Distributing Ballot Boxes
- LightOJ 1325 Distributing Chocolates
- 1325 - Distributing Chocolates
- Hadoop中Yarnrunner里面submit Job以及AM生成 至Job处理过程源码解析
- An ffmpeg and SDL Tutorial 学习笔记(一)
- 一个有关sizeof的bug
- 多进程多线程TCP服务器
- EasyUI布局,窗口,口风琴,文件上传等
- Distributing Parts CodeForces
- 在控制台输出一个九九乘法表
- JAVA语言程序设计(基础篇)第十版
- 使用HttpURLConnection发请求获取数据
- 开源漏洞检测工具
- android-support-v4/v7/v13 介绍
- Chrome浏览器中使用Android sdk search在线查看源码
- hive搭建以及使用与简介(这里就介绍最简单的嵌入式了)
- Spring mvc