Codeforces Round #283 (Div. 2) E. Distributing Parts 贪心+set二分
2 seconds
256 megabytes
standard input
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!
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, ci, di 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).
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).
3
1 3
2 4
3 5
2
1 4 2
2 5 1
YES
1 1 2
3
1 3
2 4
3 5
2
1 3 2
2 5 1
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+,M=1e6+,inf=1e9+,mod=1e9+;
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=;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=;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=,gg=;
for(int i=;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,),));
if(it==s.end())
{
gg=;
break;
}
ans[a[i].pos]=it->second;
pair < pair < int , int > , int> k=*it;
s.erase(it);
if(k.first.second>)
{
k.first.second--;
s.insert(k);
}
}
if(gg)
{
printf("NO\n");
}
else
{
printf("YES\n");
for(int i=;i<n;i++)
printf("%d ",ans[i]+);
}
return ;
}
Codeforces Round #283 (Div. 2) E. Distributing Parts 贪心+set二分的更多相关文章
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)
题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...
- Codeforces Round #283 (Div. 2) C. Removing Columns 暴力
C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力
A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #283 Div.2 D Tennis Game --二分
题意: 两个人比赛,给出比赛序列,如果为1,说明这场1赢,为2则2赢,假如谁先赢 t 盘谁就胜这一轮,谁先赢 s 轮则赢得整个比赛.求有多少种 t 和 s 的分配方案并输出t,s. 解法: 因为要知道 ...
- Codeforces Round #283 (Div. 2)
A:暴力弄就好,怎么方便怎么来. B:我们知道最多加10次, 然后每次加1后我们求能移动的最小值,大概O(N)的效率. #include<bits/stdc++.h> using name ...
- codeforces 497b// Tennis Game// Codeforces Round #283(Div. 1)
题意:网球有一方赢t球算一场,先赢s场的获胜.数列arr(长度为n)记录了每场的胜利者,问可能的t和s. 首先,合法的场景必须: 1两方赢的场数不一样多. 2赢多的一方最后一场必须赢. 3最后一场必须 ...
- Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题
B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- Xamarin.Forms学习之XAML命名空间
大家好,我又悄咪咪的来了,在上一篇的Xamarin文章中简单介绍了Xamarin的安装过程,妈蛋没想到很多小朋友很感激我,让他们成功的安装了Xamarin,然后......成功的显示了经典的两个单词( ...
- coursera 《现代操作系统》 -- 第十一周 IO系统
本周要求 错题 下列I/O控制方式中,哪一个不需要硬件支持? 中断方式 轮询方式 DMA方式 I/O处理机方式 中断方式:中断控制器 轮询方式:CPU不断查询设备以了解其是否就绪 DMA:使用到了 ...
- js的简单的逻辑算法题
比如题目:寻找1~1000之内,所有能被5整除.或者能被6整除的数字 1 for(var i = 1 ; i <= 1000 ; i++){ 2 if(i % 5 == 0 || i % 6 ...
- 【原创】学习CGLIB动态代理中遇到的问题
代码清单1 CGLIB动态代理 package wulj.proxy.cglibProxy; import java.lang.reflect.Method; import net.sf.cglib. ...
- [NOIP2018TG]旅行
[NOIP2018TG]旅行 树很简单,对每个点sort儿子,贪心走就行了 基环树呢? 如果是1e5可能不太好做 但是5000的话枚举断边就可以\(n^2\)了 #include<bits/st ...
- 常用代码块:创建httpclient 2
HttpGet httpGet = new HttpGet(url);SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(ne ...
- 介绍一下Python中webbrowser的用法?
webbrowser模块提供了一个高级接口来显示基于Web的文档,大部分情况下只需要简单的调用open()方法.webbrowser定义了如下的异常:exception webbrowser.Erro ...
- python 里安装 tensorflow 后运行出错的问题解决
如果出现一下错误: libcublas.so.8.0: cannot open shared object file: No such file or directory 原因是没有 cuda 环境, ...
- github代码托管
下载github客户端软件 1) 官网下载help.github.com 2) 百度搜索,一般用于windows7以前的系统 安装github软件 按照软件提示安装即可.不过,博主倾向使用命令行工 ...
- C# 二进制序列化(BinaryFormatter),Xml序列化(XmlSerializer),自己模拟写一个Xml序列化过程。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...