bzoj2535 2109
做过4010这题其实就水了
把图反向之后直接拓扑排序做即可,我们可以用链表来优化
每个航班的最小起飞序号就相当于在反向图中不用这个点最迟到哪
type node=record
po,next:longint;
end; var e:array[..] of node;
ans,p,h,suc,du,d,a:array[..] of longint;
i,x,y,n,m:longint; procedure add(x,y:longint);
begin
e[i].po:=y;
e[i].next:=p[x];
p[x]:=i;
end; procedure merge(x,y:longint);
begin
if h[x]= then h[x]:=h[y]
else begin
x:=h[x];
while suc[x]<> do x:=suc[x];
suc[x]:=h[y];
end;
end; function min(wh:longint):longint;
var i,x,y,t,b:longint;
begin
for i:= to n do
begin
du[i]:=d[i];
h[i]:=;
end;
for i:= to n do
if (i<>wh) and (d[i]=) then
begin
suc[i]:=h[a[i]];
h[a[i]]:=i;
end;
t:=n;
while t> do
begin
x:=h[t];
if x= then exit(t);
h[t]:=suc[h[t]];
i:=p[x];
while i<> do
begin
y:=e[i].po;
dec(du[y]);
if (y<>wh) and (du[y]=) then
begin
if a[y]<t then b:=a[y]
else b:=t;
suc[y]:=h[b];
h[b]:=y;
end;
i:=e[i].next;
end;
merge(t-,t);
dec(t);
end;
exit();
end; procedure work1;
var i,x,y,t,b:longint;
begin
for i:= to n do
begin
du[i]:=d[i];
h[i]:=;
end;
for i:= to n do
if d[i]= then
begin
suc[i]:=h[a[i]];
h[a[i]]:=i;
end;
t:=n;
while t> do
begin
x:=h[t];
ans[t]:=x;
h[t]:=suc[h[t]];
i:=p[x];
while i<> do
begin
y:=e[i].po;
dec(du[y]);
if du[y]= then
begin
if a[y]<t then b:=a[y]
else b:=t;
suc[y]:=h[b];
h[b]:=y;
end;
i:=e[i].next;
end;
merge(t-,t);
dec(t);
end;
for i:= to n- do
write(ans[i],' ');
writeln(ans[n]);
end; procedure work2;
var i:longint;
begin
for i:= to n- do
write(min(i),' ');
writeln(min(n));
end; begin
readln(n,m);
for i:= to n do
begin
read(a[i]);
if a[i]>n then a[i]:=n;
end;
for i:= to m do
begin
readln(x,y);
add(y,x);
inc(d[x]);
end;
work1;
work2;
end.
bzoj2535 2109的更多相关文章
- 贪心 POJ 2109 Power of Cryptography
题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...
- Poj 2109 / OpenJudge 2109 Power of Cryptography
1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power o ...
- poj 2109 Power of Cryptography (double 精度)
题目:http://poj.org/problem?id=2109 题意:求一个整数k,使得k满足kn=p. 思路:exp()用来计算以e为底的x次方值,即ex值,然后将结果返回.log是自然对数,就 ...
- 数据结构(树链剖分):COGS 2109. [NOIP2015] 运输计划
2109. [NOIP2015] 运输计划 ★★★ 输入文件:transport.in 输出文件:transport.out 简单对比时间限制:1 s 内存限制:256 MB [题目描 ...
- 2109 ACM 排序
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2109 题意:简单的排序问题 代码: #include<cstdio> #include< ...
- POJ 1328&&2109&&2586
这次是贪心(水笔贪心)专题. 先看1328,一道经典的导弹拦截(或者是打击?不懂背景). 大意是说在一个坐标系中有一些点(或是导弹),你要在x轴上建一些东西,它们可以拦截半径为d的圆范围中的点.问最少 ...
- HDU 2109 Fighting for HDU
http://acm.hdu.edu.cn/showproblem.php?pid=2109 Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何 ...
- bzoj 2535 && bzoj 2109 [Noi2010]Plane 航空管制——贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2535 https://www.lydsy.com/JudgeOnline/problem.p ...
- BZOJ2535 [Noi2010]Plane 航空管制 【贪心 + 堆】
题目链接 BZOJ2535 题解 航班之间的关系形成了一个拓扑图 而且航班若要合法,应尽量早出发 所以我们逆拓扑序选点,能在后面出发的尽量后面出发,不会使其它点变得更劣,容易知是正确的 第二问只需枚举 ...
随机推荐
- 关于 iOS 刷新效果实现的思路 和 mac软件网址推荐
有一次面试,突然有个人问了我一个问题:MJRefresh的原理是什么? 我说这种效果可以有两种方法实现: 1. UIRefreshControl 2. 通过监听scrollview的偏移量,自定义 ...
- HTTP 错误 500.21 - Internal Server ErrorHTTP
应用程序“DEFAULT WEB SITE/WINDRP_TB/TBFXWS”中的服务器错误Internet Information Services 7.5错误摘要HTTP 错误 500.21 - ...
- Codeforces Round #302 (Div. 2) D. Destroying Roads 最短路
题目链接: 题目 D. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input ...
- unity与Android相互调用
原地址:http://www.cnblogs.com/ayanmw/p/3727782.html 现在unity 导出的android客户端需要调用 Android 的支付SDK,但是unity与an ...
- 轻轻修改配置文件完成 OpenStack 监控
当我们使用虚拟化云平台 OpenStack 时,必然要时时监控其虚拟机性能,随着近年企业级数据中心的不断发展,像混合虚拟化环境的业务需求也在持续增长中,因而也随之带来的监控需求更显重要,所以小编带来一 ...
- NSOJ10050 Newspaper Headline
题意:给你一个<10^4的S串和<10^6的T串,通过将S串重复k次,然后将其中一些多余的字母删掉可以获得T串,问k最小是多少,没有的话输出1. 思路:对于每个T串里的字母,我们从左到右扫 ...
- 编写高性能JavaScript【转】
英文链接:Writing Fast, Memory-Efficient JavaScript 很多JavaScript引擎,如Google的V8引擎(被Chrome和Node所用),是专门为需要快速执 ...
- gulp下livereload和webserver实现本地服务器下文件自动刷新
一.前言 node从v0.10.26升级(为了匹配autoprefixer)到v5.3.0后出现了gulp插件兼容问题,在nodejs下各种新的插件出现问题,需要重新配置.livereload实现ch ...
- java基础知识回顾之java Thread类学习(五)--java多线程安全问题(锁)同步的前提
这里举个例子讲解,同步synchronized在什么地方加,以及同步的前提: * 1.必须要有两个以上的线程,才需要同步. * 2.必须是多个线程使用同一个锁. * 3.必须保证同步中只能有一个线程在 ...
- hdu 4277 USACO ORZ
没什么好方法,只能用dfs了. 代码如下: #include<iostream> #include<cstring> #include<cstdio> #inclu ...