题目链接

BZOJ2535

题解

航班之间的关系形成了一个拓扑图

而且航班若要合法,应尽量早出发

所以我们逆拓扑序选点,能在后面出发的尽量后面出发,不会使其它点变得更劣,容易知是正确的

第二问只需枚举航班\(x\),拓扑排序时忽视\(x\),最后无法选点时就是\(x\)最早的时间

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<map>
#include<cstring>
#include<algorithm>
#define LL long long int
#define Redge(u) for (register int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (register int i = 1; i <= (n); i++)
#define res register
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 2005,maxm = 20005,INF = 1000000000;
inline int read(){
res int out = 0,flag = 1; res char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int n,m,inde[maxn],K[maxn],val[maxn],ans[maxn];
int h[maxn],ne;
struct EDGE{int to,nxt;}ed[maxm];
inline void build(int u,int v){
ed[++ne] = (EDGE){v,h[u]}; h[u] = ne;
inde[v]++;
}
priority_queue<cp> q;
inline void solve1(){
REP(i,n){
val[i] = inde[i];
if (!val[i]) q.push(mp(K[i],i));
}
cp u;
for (int i = n; i; i--){
u = q.top(); q.pop();
ans[i] = u.second;
Redge(u.second){
if (!(--val[to = ed[k].to])) q.push(mp(K[to],to));
}
}
REP(i,n){
printf("%d",ans[i]);
if (i < n) putchar(' ');
}puts("");
}
inline int solve2(int x){
while (!q.empty()) q.pop();
REP(j,n) val[j] = inde[j]; val[x] = n;
REP(j,n) if (!val[j]) q.push(mp(K[j],j));
cp u;
for (res int j = n; j; j--){
if (q.empty()) return j;
u = q.top(); q.pop();
if (u.first < j) return j;
Redge(u.second) if (!(--val[to = ed[k].to])) q.push(mp(K[to],to));
}
return 1;
}
int main(){
n = read(); m = read();
REP(i,n) K[i] = read();
int a,b;
REP(i,m) {
a = read(); b = read();
build(b,a);
}
solve1();
REP(i,n) printf("%d ",solve2(i));
return 0;
}

BZOJ2535 [Noi2010]Plane 航空管制 【贪心 + 堆】的更多相关文章

  1. BZOJ2535 [Noi2010]Plane 航空管制2

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...

  2. BZOJ2535: [Noi2010]Plane 航空管制2(拓扑排序 贪心)

    题意 题目链接 Sol 非常妙的一道题. 首先不难想到拓扑排序,但是直接对原图按\(k\)从小到大拓扑排序是错的.因为当前的\(k\)大并不意味着后面的点\(k\)也大 但是在反图上按\(k\)从大到 ...

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

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

  4. bzoj 2109: [Noi2010]Plane 航空管制

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...

  5. 2109&2535: [Noi2010]Plane 航空管制 - BZOJ

    Description世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上, ...

  6. BZOJ 2535: [Noi2010]Plane 航空管制2

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...

  7. BZOJ2109: [Noi2010]Plane 航空管制

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...

  8. bzoj 2535: [Noi2010]Plane 航空管制2【拓扑排序+堆】

    有个容易混的概念就是第一问的答案不是k[i]字典序最小即可,是要求k[i]大的尽量靠后,因为这里前面选的时候是对后面有影响的(比如两条链a->b c->d,ka=4,kb=2,kc=3,k ...

  9. [BZOJ2109][NOI2010]航空管制(贪心+拓扑)

    2109: [Noi2010]Plane 航空管制 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1227  Solved: 510[Submit][ ...

随机推荐

  1. C/C++程序基础 (十一)标准模板库

    标准模板库 标准模板库在标准函数库的定位 迭代器(类似指针)保证算法(常用算法)和容器(数据结构)的结合. vector的实现 底层实现是动态数组,所以支持随机访问. 内部是动态数组,随着insert ...

  2. 8-1 python 接口开发(提供数据、返回session_id)

    1.接口开发,根据不同查询条件返回数据库查询结果 import flask import tools import json server = flask.Flask(__name__) #新建一个服 ...

  3. python--Matplotlib(一)

    基础知识薄弱的同学可以看看一下博客 https://www.cnblogs.com/dev-liu/p/pandas_plt_basic.html https://blog.csdn.net/Notz ...

  4. 访问远程mysql数据库,出现报错,显示“1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server“

    在使用Navicat for MySQl访问远程mysql数据库,出现报错,显示“1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to t ...

  5. Linux系统完整安装在虚拟机Mini

    打开VMware Workstation虚拟机,然后如下图一步到位: 此处只是简单的安装Linux系统,要想查看安装后的IP等配置看: https://www.cnblogs.com/gentle-a ...

  6. QWidget 自带的最大化,最小化,关闭按键的设置

    使用函数 setWindowFlags 参数: CustomizeWindowHint 去掉窗口所有自带按钮 Qt::CustomizeWindowHint | Qt::WindowCloseButt ...

  7. HDU 6386 Age of Moyu

    Problem Description Mr.Quin love fishes so much and Mr.Quin’s city has a nautical system,consisiting ...

  8. python正则表达式01--贪心算法和非贪心算法findall()

    import re st = 'asdfasxxixxdafqewxxlovexxsadawexxyouxxas' # . #点匹配除换行符外的任意字符 a0 = re.findall('xx.',s ...

  9. Best Practices in JavaScript

    Some items you should konw : Graceful degradation : ensuring that your web pages still work without ...

  10. 十、mysql之索引原理与慢查询优化

    mysql之索引原理与慢查询优化 一.介绍 1.什么是索引? 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,在生产环境中,我们遇到最多的,也是最容易出问题的,还 ...