codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)
题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次。问一种方式站满n个区间。
两种区间都用先x后y的升序排序。对于当前的区间[ai,bi],将ci值小于当前ai的全部放入multiset。再lower_bound查第一个>=bi的就是答案。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
const double EPS=1e-;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
struct nd{
int a,b,k,id;
bool operator<(const nd&rbs)const
{
if(a!=rbs.a)return a<rbs.a;
else return b<rbs.b;
}
}; struct cmp{
bool operator()(const nd&x,const nd&y)const
{
return x.b<y.b;
}
}; int ans[SZ]; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
int n;
cin>>n;
vector<nd> vct;
for(int i=;i<n;++i)
{
nd tmp;
cin>>tmp.a>>tmp.b;
tmp.id=i;
vct.push_back(tmp);
}
sort(vct.begin(),vct.end());
int m;
cin>>m;
vector<nd> peo;
for(int i=;i<m;++i)
{
nd tmp;
cin>>tmp.a>>tmp.b>>tmp.k;
tmp.id=i+;
peo.push_back(tmp);
}
sort(peo.begin(),peo.end());
multiset<nd,cmp> st;
bool ok=;
vector<int> res;
for(int i=,j=;i<vct.size();++i)
{
nd cur=vct[i];
for(;j<peo.size();++j)
{
if(peo[j].a<=cur.a)
{
st.insert(peo[j]);
}
else break;
}
vector<nd> mvd;
//cout<<"sz: "<<st.size()<<endl;
for(;!st.empty();)
{
if(st.lower_bound(cur)==st.end())
{
ok=;
break;
}
auto it=st.lower_bound(cur);
nd top=*it;
//cout<<" "<<i<<" "<<top.id<<" "<<top.k<<endl;
st.erase(it);
--top.k;
if(top.k>=)
{
st.insert(top);
}
else continue;
res.push_back(top.id);
ans[cur.id]=top.id;
break; }
}//
if(ok&&n==res.size())
{
cout<<"YES"<<endl;
for(int i=;i<res.size();++i)
{
if(i)cout<<" ";
cout<<ans[i];
}
cout<<endl;
}
else cout<<"NO"<<endl;
return ;
}
codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)的更多相关文章
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- 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 standa ...
- 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 ...
随机推荐
- Linux服务器配置---ftp限制ip
ftp限制IP 1.通过vsftpd的配置文件以及“hosts.deny”和“hosts.allow”文件设置允许某个ip地址访问 1)修改配置文件“/etc/vsftpd/vsftpd.conf”中 ...
- Linux配置自动时间同步
Linux配置自动时间同步时间同步命令:ntpdate -s time.windows.com自动时间同步:让linux从time.windows.com自动同步时间vi /etc/crontab加上 ...
- nginx的权限问题(Permission denied)解决办法
nginx的权限问题(Permission denied)解决办法 一个nginx带多个tomcat集群环境,老是报如下错误:failed (13: Permission denied) while ...
- php 截取字符串第一个字符,截取掉字符串最后一个字符的方法
php 截取字符串第一个字符,php截取掉字符串最后一个字符的方法: $frist = substr( $c_url, 0, 1 ); $delete_last = substr(base_url() ...
- Python之路----迭代器与生成器
一.迭代器 L=[1,,2,3,4,5,] 取值:索引.循环for 循环for的取值:list列表 dic字典 str字符串 tuple元组 set f=open()句柄 range() enumer ...
- 干货:Java并发编程必懂知识点解析
本文大纲 并发编程三要素 原子性 原子,即一个不可再被分割的颗粒.在Java中原子性指的是一个或多个操作要么全部执行成功要么全部执行失败. 有序性 程序执行的顺序按照代码的先后顺序执行.(处理器可能会 ...
- mp4v2 基本知识
mp4v2 和mp4的一些基础知识 由于项目需要做mp4文件的合成(264+aac)和mp4文件的解析: MP4文件本身就是一个容器,对于视频来说就是把不同的内容放按照mp4的规则存放而已: 如果完全 ...
- ELK学习笔记之CentOS 7下ELK(6.2.4)++LogStash+Filebeat+Log4j日志集成环境搭建
0x00 简介 现在的公司由于绝大部分项目都采用分布式架构,很早就采用ELK了,只不过最近因为额外的工作需要,仔细的研究了分布式系统中,怎么样的日志规范和架构才是合理和能够有效提高问题排查效率的. 经 ...
- 详解C中的volatile关键字【转】
本文转载自:http://www.cnblogs.com/yc_sunniwell/archive/2010/06/24/1764231.html volatile提醒编译器它后面所定义的变量随时都有 ...
- 【基础配置】Dubbo的配置及使用
1. Dubbo是什么? Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.简单的说,dubbo就是个服务框架,如果没有分布式的需求,其实是不需 ...