Gym - 102059D 2018-2019 XIX Open Cup, Grand Prix of Korea D. Dumae 贪心+堆
题意:有3e5个人排成一列,然后Li,Ri表示每个人可以站在[Li,Ri]中的一个,然后M(1e6)个限制条件,某个人一定要在某个人前面,求一种合法方案,无解输出-1
题解:首先可以想到对于限制条件,先进行拓扑排序,如果不能则无解
针对拓扑排序的结果,可以更精确每个人站的位置的区间[Li,Ri]
然后从后往前进行考虑,我们考虑每个位置由谁来坐比较好,那我们策略是,R能覆盖这个位置的中,L最大的那一个来最优,
我们一直维护一个R的堆,每次我们将R超过当前位置的人都丢进一个新的堆里,这个堆按L大来排序,再使用最大的那个L
如此贪心做完,不行则无解
#include<bits/stdc++.h>
#define lld long long
#define N 300005
using namespace std;
vector<int> g[N];
int n,m,du[N],x,y,ans[N];
struct rec
{
int l,r,id;
bool operator <(const rec& a)const
{
if (r!=a.r) return r<a.r;
return l>a.l;
}
}a[N];
struct ssy
{
int l,r,id;
bool operator <(const ssy& a)const
{
return l<a.l;
}
}b[N];
int ask()
{
priority_queue<ssy>q;
priority_queue<rec>qq;
ssy st;
while (!q.empty()) q.pop();
while (!qq.empty()) qq.pop();
for (int i=;i<=n;i++) if (du[i]==) qq.push(a[i]);
for (int i=n;i>=;i--)
{
while (!qq.empty())
{
if (qq.top().r<i) break;
q.push(b[qq.top().id]);
// cout << b[qq.top().id].id << endl;
qq.pop();
}
if (q.empty() || q.top().l>i) return ;
st=q.top();
// cout<<st.id << endl;
q.pop(); //cout<<"id"<<st.id<<endl;
ans[i]=st.id; for (int j=;j<g[st.id].size();j++)
{
int u=g[st.id][j];
du[u]--;
if (du[u]==) qq.push(a[u]);
}
}
return ;
}
int c[N];
bool dfs(int u)
{
c[u]=-;
for (int v=;v<g[u].size();v++)
{
int to=g[u][v];
if (c[to]<)
{
//cout<<"u xxx:"<<u<<endl;
//cout<<"1 xxx:"<<to<<endl;
return ;
}else
if (!c[to] && !dfs(to))
{
//cout<<"u xxx:"<<u<<endl;
//cout<<"1 xxx:"<<to<<endl;
return ;
}
a[u].l=max(a[u].l,a[to].l+);
b[u].l=a[u].l;
}
c[u]=;
return ;
}
bool toposort()
{
memset(c,,sizeof(c));
for (int u=;u<=n;u++) if (!c[u])
if (!dfs(u)) return ;
return ;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
scanf("%d%d",&a[i].l,&a[i].r);a[i].id=i;
b[i].l=a[i].l;
b[i].r=a[i].r;
b[i].id=a[i].id;
}
for (int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
g[y].push_back(x);
du[x]++;
}
if (!toposort()) printf("-1\n");else
if (!ask()) printf("-1\n");else
for (int i=;i<=n;i++) printf("%d\n",ans[i]); //for (int i=1;i<=n;i++) cout<<a[i].l<<" "<<a[i].r<<endl;
}
Gym - 102059D 2018-2019 XIX Open Cup, Grand Prix of Korea D. Dumae 贪心+堆的更多相关文章
- 【GYM 102059】2018-2019 XIX Open Cup, Grand Prix of Korea
		
vp了一场gym,我又开心地划水了. A. Coloring Roads 题意:给定一棵树,树边一开始都是无色的,每次操作可以把一个点到根的路径染成某个颜色,每次询问当前树上出现过某个次数的颜色种数. ...
 - 2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2) GYM 102058 F  SG函数
		
http://codeforces.com/gym/102058/problem/F 题意:平面上n个点 两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...
 - Gym.102059:   2018-2019 XIX Open Cup, Grand Prix of Korea(寒假gym自训第一场)
		
整体来说,这一场的质量比较高,但是题意也有些难懂. E.Electronic Circuit 题意: 给你N个点,M根线,问它是否是一个合法的电路. 思路: 一个合法的电路,经过一些串联并联关系, ...
 - Codeforces gym102058 J. Rising Sun-简单的计算几何+二分 (2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2))
		
J. Rising Sun time limit per test 1.0 s memory limit per test 1024 MB input standard input output st ...
 - 2018-2019 XIX Open Cup, Grand Prix of Korea B - Dev, Please Add This!
		
B - Dev, Please Add This! 思路: 对于每一个经过 '*' 的横线和竖线看成一个整体,设他们分别为分量x和分量y 用2-sat考虑这个问题, 如果要经过 '*' ,那么x和y至 ...
 - XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Korea
		
A. Donut 扫描线+线段树. #include<cstdio> #include<algorithm> using namespace std; typedef long ...
 - 【推导】【数学期望】【冒泡排序】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem C. Earthquake
		
题意:两地之间有n条不相交路径,第i条路径由a[i]座桥组成,每座桥有一个损坏概率,让你确定一个对所有桥的检测顺序,使得检测所需的总期望次数最小. 首先,显然检测的时候,是一条路径一条路径地检测,跳跃 ...
 - 【线段树】【扫描线】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem A. Donut
		
题意:平面上n个点,每个点带有一个或正或负的权值,让你在平面上放一个内边长为2l,外边长为2r的正方形框,问你最大能圈出来的权值和是多少? 容易推出,能框到每个点的 框中心 的范围也是一个以该点为中心 ...
 - 2020-2021 Winter Petrozavodsk Camp, Belarusian SU Contest (XXI Open Cup, Grand Prix of Belarus) 题解
		
题目列表 C. Brave Seekers of Unicorns D. Bank Security Unification G. Biological Software Utilities I. B ...
 
随机推荐
- tarjan求强连通分量模板
			
什么是强连通分量? 百度百科 有向图强连通分量:在有向图G中,如果两个顶点vi,vj间(vi>vj)有一条从vi到vj的有向路径,同时还有一条从vj到vi的有向路径,则称两个顶点强连通(stro ...
 - Window下的———TOMCAT环境的配置
			
1. 先去官方网站下载需要的猫(tomcat) http://tomcat.apache.org/ 2.下载好包,然后解压出来,放在你需要的位置上 3.去到配环境变量的地方,进行相应的环境配置 ...
 - JavaScript 面向对象的编程(三) 类的继承
			
定义父类和子类的继承关系 //声明父类 function SuperClass(){ this.superValue = true; } //为父类添加共有方法 SuperClass.prototyp ...
 - [已解决]运行gunicorn失败:[ERROR] Connection in use 127.0.0.1 8080
			
最近重新部署了一下应用程序,之后重新运行gunicorn,使用如下命令: gunicorn -b 0.0.0.0:8000 manage:app --reload 之后出现了一堆错误,具体错误内容如下 ...
 - unigui的ini文件读写【6】
			
procedure THeaderFooterForm.writerParas; var IniFile : TIniFile; begin try IniFile:=TIniFile.Create( ...
 - 解决Web部署 woff字体 404错误
			
问题:刚刚在IIS上部署web项目的时候,发现浏览器总是报找不到woff字体的错误.导致浏览器加载字体报404错误. 原因:因为服务器IIS不认WOFF这个文件类型,只要在IIS上添加MIME 类型即 ...
 - HDU——1787  GCD Again
			
题意: 在一次acm竞赛之后,你花了一些时间去思考和尝试解决那些未解决的问题吗? 不知道?哦,当你想成为“大牛”的时候,你就必须这样做. 现在你会发现,这个问题是如此熟悉: 两个正整数a和b的最大GC ...
 - Android 内存管理
			
1.Activity中的对象生命周期勿大于Activity的生命周期.OOM演示样例代码例如以下: private static Drawable sBackground; @Override pro ...
 - jquery 1.9以上新版本不支持toggle()的解决方法
			
原文:http://blog.csdn.net/u011061889/article/details/50397462 参考: http://www.cnblogs.com/lionden/archi ...
 - V Server Ubuntu
			
Ubuntu下代理伺服器通常使用squid 安裝 sudo apt-get install squid 修改squid.conf配置 sudo vim /etc/squid/squid.conf 公司 ...