做过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的更多相关文章

  1. 贪心 POJ 2109 Power of Cryptography

    题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...

  2. 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 ...

  3. poj 2109 Power of Cryptography (double 精度)

    题目:http://poj.org/problem?id=2109 题意:求一个整数k,使得k满足kn=p. 思路:exp()用来计算以e为底的x次方值,即ex值,然后将结果返回.log是自然对数,就 ...

  4. 数据结构(树链剖分):COGS 2109. [NOIP2015] 运输计划

    2109. [NOIP2015] 运输计划 ★★★   输入文件:transport.in   输出文件:transport.out   简单对比时间限制:1 s   内存限制:256 MB [题目描 ...

  5. 2109 ACM 排序

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2109 题意:简单的排序问题 代码: #include<cstdio> #include< ...

  6. POJ 1328&&2109&&2586

    这次是贪心(水笔贪心)专题. 先看1328,一道经典的导弹拦截(或者是打击?不懂背景). 大意是说在一个坐标系中有一些点(或是导弹),你要在x轴上建一些东西,它们可以拦截半径为d的圆范围中的点.问最少 ...

  7. HDU 2109 Fighting for HDU

    http://acm.hdu.edu.cn/showproblem.php?pid=2109 Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何 ...

  8. bzoj 2535 && bzoj 2109 [Noi2010]Plane 航空管制——贪心

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2535 https://www.lydsy.com/JudgeOnline/problem.p ...

  9. BZOJ2535 [Noi2010]Plane 航空管制 【贪心 + 堆】

    题目链接 BZOJ2535 题解 航班之间的关系形成了一个拓扑图 而且航班若要合法,应尽量早出发 所以我们逆拓扑序选点,能在后面出发的尽量后面出发,不会使其它点变得更劣,容易知是正确的 第二问只需枚举 ...

随机推荐

  1. ruby 格式化当前日期时间

    ruby 格式化当前日期时间 ruby 用Time类获取当前时间. t = Time.new puts t 可以看到输出的是(我现在运行的时间): Sat Jan 29 10:45:22 +0800 ...

  2. android开发之socket快传文件以及消息返回

    应用场景: 两台android机器:一台自建wifi热点,另一台搜索到,连接该wifi热点.之后再通过socket传递消息,文件等,当服务器端接收到消息之后会返回对应的应答消息: 注意点:接收到消息之 ...

  3. NopCommerce——Web层中的布局页

    援引上一篇文章关于nopcommerce源代码结构的翻译:“Nop.Web也是一个MVC Web应用程序项目,一个公有区域的展示层.它就是你实际能够运行的应用程序.它是应用程序的启动项目”.对于nop ...

  4. windows server 2008 下安装openmeetings 2.2.0

    经过两天的痛苦经历,终于完成了openmeetings的安装部署.其实步骤都很简单,只是网上的资料都是英文的,而且很多教程都是针对openmeeting之前的版本,导致我在部署的时候走了很多弯路.网上 ...

  5. jquery css 简单笔记

    内容 要点:清空表单中所有数据,除去 button,submit,reset,hidden 的数据 $(':input','#myform') .not(':button, :submit, :res ...

  6. POJ 2255 Tree Recovery(根据前序遍历和中序遍历,输出后序遍历)

    题意:给出一颗二叉树的前序遍历和中序遍历的序列,让你输出后序遍历的序列. 思路:见代码,采用递归. #include <iostream> #include <stdio.h> ...

  7. Elasticsearch 学习~

    http://cloud.51cto.com/art/201505/476322.htmEs https://www.gitbook.com/book/asdgh000/mongodb-elastic ...

  8. zoj 3599 Game 博弈论

    K倍动态减法游戏!!! 链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4683 代码如下: #include<ios ...

  9. 关于C#中timer类

    ·关于C#中timer类 在C#里关于定时器类就有3个 1.定义在System.Windows.Forms里 2.定义在System.Threading.Timer类里 3.定义在System.Tim ...

  10. 欧拉工程第72题:Counting fractions

    题目链接:https://projecteuler.net/problem=72 真分数;n/d 当d ≤ 1,000,000时候的真分数有多少个 public class P72{ void run ...