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 ...
随机推荐
- Convert.ToInt32(string '000000003') 变成了 3
Convert.ToInt32(string '000000003') 变成了 3 但是在查询的时候需要用的是string 这里的convert.toint32 反而起了坏作用,不是所有的时候都要用c ...
- cocos2d-x设计模式发掘之一:单例模式
作者: firedragonpzy 原地址:http://www.firedragonpzy.com.cn/index.php/archives/1781 本系列文章我将和大家一起来发掘coc ...
- 1028 大数乘法 V2(FFT or py)
1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B ...
- EasyGBS国标流媒体服务器GB28181国标方案安装使用文档
EasyGBS - GB28181 国标方案安装使用文档 下载 安装包下载,正式使用需商业授权, 功能一致 在线演示 在线API 架构图 EasySIPCMS SIP 中心信令服务, 单节点, 自带一 ...
- 如何用 JavaScript 控制 Arduino?
Arduino 运行 C 语言,而主控端运行 JavaScript,一次要编写和维护两种程序.既然浏览器和服务器都用 JavaScript,若 Arduino 也能用 JavaScript 控制,那岂 ...
- 《挑战程序设计竞赛》1.6 轻松热身 POJ1852
Ants Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12782 Accepted: 5596 Description ...
- 《UNIX网络编程》 -- 第五章
str_cli 和 str_echo 函数 需要先弄清楚 3.9 readn.writen 和 readline 函数 str_cli void str_cli(FILE *fp, int sockf ...
- 人工智能-baidu-aip语音识别(语音转文字)
做这个之前,需要在电脑上安装FFmpeg工具,将要转的语音格式转为PCM格式.FFmpeg不需要安装,下载后,打开bin文件夹,然后将路径放在系统环境变量里.记住,要关闭所有打开的Pycharm,然后 ...
- MySQL第一天
数据库课程体系 在PHP阶段,将数据库分为三个阶段: 基础阶段(就业班第一个阶段): 6天, mysql数据库的基本操作(增删改查), 以及一些高级操作(视图, 触发器,函数,存储过程等), ...
- 0405-服务注册与发现-客户端负载均衡-Ribbon 同Eureka使用,Ribbon脱离Eureka使用
一.Ribbon 同Eureka使用,注意事项 前几节一同使用,注意事项: 如果没有其他区域数据源,则根据客户端配置进行猜测(与实例配置相反).能够获取eureka.client.availabili ...