题目链接

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. Map the Debris -freecodecamp算法题目

    Map the Debris 1.要求 返回一个数组,其内容是把原数组中对应元素的平均海拔转换成其对应的轨道周期. 原数组中会包含格式化的对象内容,像这样 {name: 'name', avgAlt: ...

  2. OceanBase安装

    背景: OceanBase是阿里巴巴.蚂蚁金服自主研发的可扩展的分布式关系数据库,实现了数千亿条记录.数百 TB 数据上的跨行跨表事务,主要支持支付宝核心的交易.支付.会员和账务系统等 OLTP 和  ...

  3. django连接mysql数据库配置,出现no module named mysqldb报错

    作为一个菜鸟运维也是要有梦想的,万一学会了python走向人生巅峰了呢.好吧,都是瞎想,今天主要介绍下django配置,最近也开始摸索这个牛b框架了,当然大佬肯定不屑一顾,都是照顾照顾我们这些菜鸟初学 ...

  4. 通过Samba实现Linux与Windows间的文件共享

    Samba Samba,是用来让Linux系列的操作系统与Windows操作系统的SMB/CIFS(Server Message Block/Common Internet File System)网 ...

  5. 2、spring boot 配置文件

    配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的: •application.properties •application.yml 配置文件的作用:修改SpringBoot自 ...

  6. MySQL之查询性能优化(四)

    优化特定类型的查询 COUNT()的作用 COUNT()是一个特殊函数,有两个非常不同的作用:它可以统计某个列值的数量,也可以统计行数.在统计列值时要求列值是非空的(不统计NULL). 如果在COUN ...

  7. mutable c++

    The keyword mutable is used to allow a particular data member of const object to be modified. This i ...

  8. druid sqlparser使用例子

    package com.alibaba.druid.bvt.sql.mysql; import java.util.List; import org.junit.Assert; import com. ...

  9. DOS程序员手册(八)

    备,就可以从程序中访问驱动程序.可以用句柄功能调用来     打开设备(见列表12.9)         列表12.9           /*example.C               List ...

  10. 《数据结构》C++代码 栈与队列

    线性表中,先进先出的叫队列,先进后出的叫栈.队列常用于BFS,而在函数递归层数过高时,需要手动实现递归过程,这时候便需要写一个“手动栈”. 有时候,我们会有大量数据频繁出入队列,但同时存在其内的元素却 ...