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 ...
随机推荐
- 【BZOJ2226】[Spoj 5971] LCMSum 莫比乌斯反演(欧拉函数?)
[BZOJ2226][Spoj 5971] LCMSum Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n ...
- The Intriguing Obsession
C. The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input s ...
- 1282 时钟(最小表示法+hash)
1282 时钟 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 有N个时钟,每个时钟有M个指针,P个刻度.时钟是圆形的,P个刻度均分整 ...
- C#动态删除控件
foreach (Control var in panel.Controls) { if (var is Billet) { panel.Controls.Remove(var); var.Dispo ...
- js对多行字符串的处理
f = [] g = str(f) h = ''.join(f) dic_ = () gd = str(dic_) hd = ''.join(dic_) 0 老板1 北京2 上海3 天津4 重庆5 河 ...
- 安装git和配置
首先更新系统 yum -y update 安装依赖的包 yum -y install curl-devel expat-devel gettext-devel openssl-devel zli ...
- Android系统移植与调试之------->如何修改Android设备存储盘符名称与Android设备的型号
一.修改Android设备存储盘符名称 (注:TBDG1073为我的项目名称) 1.修改device/other/TBDG1073/system.prop 文件 2.修改ro.media.patiti ...
- java基础:父类与子类之间变量和方法的调用
1)父类构造函数 java中当调用某个类的构造方法的时候,系统总会调用父类的非静态初始化块进行初始化,这个调用是隐式的,而且父类的静态初始化代码 块总是会被执行,接着调用父类的一个或者多个构造器执行初 ...
- Python基础-生成器和迭代器
生成器都是迭代器,迭代器不一定是生成器 def fansik(max): n, before, after = 0, 0, 1 while n < max: print(before) befo ...
- 【转载】格式化存储装置成为 Ext2/Ext3/Ext4 档案系统
格式化 用系统管理员帐户 (即 root) 身份打「mkfs -t ext2|ext3|ext4 储存装置」: mkfs -t ext3 /dev/sdb5 要格式化档案系统为 Ext2,亦可以直接使 ...