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 题解 航班之间的关系形成了一个拓扑图 而且航班若要合法,应尽量早出发 所以我们逆拓扑序选点,能在后面出发的尽量后面出发,不会使其它点变得更劣,容易知是正确的 第二问只需枚举 ...
随机推荐
- Team Homework #1 学长“学霸英语学习软件”试用
简介: 一款英语单词记忆和管理辅助软件. 基本功能: 内置GRE词汇及其常考形态.Webster英语解释 单词发音功能 单词测验模式 简易词典功能 基本界面 词库单词读取 单词测试 优点: 1.界面简 ...
- Careercup - Facebook面试题 - 23594662
2014-05-02 03:19 题目链接 原题: Given a sequence of numbers A() ..A(n), find the continuous subsequenceA(i ...
- Python的map、filter、reduce函数 [转]
1. map函数func作用于给定序列的每个元素,并用一个列表来提供返回值. map函数python实现代码: def map(func,seq): mapped_seq = [] fo ...
- 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)
// test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- 在线最优化求解(Online Optimization)之三:FOBOS
在线最优化求解(Online Optimization)之三:FOBOS FOBOS (Forward-Backward Splitting)是由John Duchi和Yoram Singer提出的[ ...
- uva 10910
简单dp /************************************************************************* > Author: xlc2845 ...
- 查看 dmp 字符集
用Oracle的exp工具导出的dmp文件也包含了字符集信息,dmp文件的第2和第3个字节记录了dmp文件的字符集.如果dmp文件不大,比如只有几M或几十M,可以用UltraEdit打开(16进制方式 ...
- Proxmox虚拟机增加硬盘容量
1.首先在虚拟机控制台选择调整硬盘容量,弹出窗口为增加的容量 2.重启虚拟机,用fdisk –l查看新增容量是否被识别 3.用cfdisk创建分区,分区格式为Primary 8e (Linux LVM ...
- poj 2387 Til the Cows Come Home (最短路,dijkstra模版题)
题目 #define _CRT_SECURE_NO_WARNINGS #include<string.h> #include<stdio.h> #include<math ...
- Asp.Net缓存(1)
知其根本,方能应用.MSDN上的缓存讲解.先看原来讲解. Asp.Net缓存概述 通常,应用程序可以将那些频繁访问的数据,以及那些需要大量处理时间来创建的数据存储在内存中,从而提高性能. 在这些情况下 ...