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 ...
随机推荐
- c#: using Microsoft.Office.Interop.Excel 异常
解决方法: Project>Reference>右键Add Reference...>Choose Microsoft Excel 15.0 Object Library
- [转载] My97DatePicker日历实现开始日期小于结束日期验证
<tr align='center'> <td align="right">开始日期: </td> <td align="lef ...
- MongoDB ----基于分布式文件存储的数据库
参考: http://www.cnblogs.com/huangxincheng/category/355399.html http://www.cnblogs.com/daizhj/category ...
- Python Web学习笔记之SSL,TLS,HTTPS
一. SSL 1. SSL简介 SSL协议位于TCP/IP协议与各种应用层协议之间,为数据通讯提供安全支持.SSL协议可分为两层: SSL记录协议(SSL Record Protocol):它建立在可 ...
- Linux 环境 HTTP 服务器
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <netinet/in ...
- luogu 1004 方格取数
题目描述 设有 $N \times N$ 的方格图 $(N \le 9)$ ,我们将其中的某些方格中填入正整数,而其他的方格中则放入数字 $0$ .如下图所示(见样例): A 0 0 0 0 0 0 ...
- Pc端css初始化
@charset "UTF-8"; /**css初始化**/ body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd ...
- Ubuntu 上 执行命令 java -version 显示 没有那个文件或目录
解决方法 执行 which java 发现默认java目录:/usr/bin/java . 查看 JAVA_HOME 路径:$JAVA_HOME,得到 /usr/local/java/jdk1.7.0 ...
- 用 C# 计算 与 java 一致的unix时间戳 (长时间整形 如:1476956079961)
背景: 调用java提供接口,需要长时间整形作为验证. 预备知识: 1. java 的 System.currentTimeMillis() 计算的长整型,是从1970年1月1日开始,截止当前的毫秒数 ...
- 51nod 1199 Money out of Thin Air(线段树+树剖分)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1199 题意: 思路:因为是一棵树,所以需要把它剖分一下再映射到线段树上, ...