BZOJ2535 [Noi2010]Plane 航空管制 【贪心 + 堆】
题目链接
题解
航班之间的关系形成了一个拓扑图
而且航班若要合法,应尽量早出发
所以我们逆拓扑序选点,能在后面出发的尽量后面出发,不会使其它点变得更劣,容易知是正确的
第二问只需枚举航班\(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 航空管制 【贪心 + 堆】的更多相关文章
- BZOJ2535 [Noi2010]Plane 航空管制2
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...
- BZOJ2535: [Noi2010]Plane 航空管制2(拓扑排序 贪心)
题意 题目链接 Sol 非常妙的一道题. 首先不难想到拓扑排序,但是直接对原图按\(k\)从小到大拓扑排序是错的.因为当前的\(k\)大并不意味着后面的点\(k\)也大 但是在反图上按\(k\)从大到 ...
- bzoj 2535 && bzoj 2109 [Noi2010]Plane 航空管制——贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2535 https://www.lydsy.com/JudgeOnline/problem.p ...
- bzoj 2109: [Noi2010]Plane 航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...
- 2109&2535: [Noi2010]Plane 航空管制 - BZOJ
Description世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上, ...
- BZOJ 2535: [Noi2010]Plane 航空管制2
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...
- BZOJ2109: [Noi2010]Plane 航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...
- bzoj 2535: [Noi2010]Plane 航空管制2【拓扑排序+堆】
有个容易混的概念就是第一问的答案不是k[i]字典序最小即可,是要求k[i]大的尽量靠后,因为这里前面选的时候是对后面有影响的(比如两条链a->b c->d,ka=4,kb=2,kc=3,k ...
- [BZOJ2109][NOI2010]航空管制(贪心+拓扑)
2109: [Noi2010]Plane 航空管制 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1227 Solved: 510[Submit][ ...
随机推荐
- mac上配置java jdk环境
访问Oracle官网 http://www.oracle.com,浏览到首页的底部菜单 ,然后按下图提示操作: 2.点击“JDK DOWNLOAD”按钮: 3.选择“Accept Lisence Ag ...
- datatable 默认按某字段排序
"columns": [ { data: null}, { data: 'name'}, { data: 'birthday'} ], "order": [[ ...
- Spring Security 简介
本文引自:https://blog.csdn.net/xlecho/article/details/80026527 在 Web 应用开发中,安全一直是非常重要的一个方面.安全虽然属于应用的非功能性需 ...
- linux C 数组与指针
linux C 数组与指针 一.数组 数组是同一数据类型的一组值:属于引用类型,因此数组存放在堆内存中:数组元素初始化或给数组元素赋值都可以在声明数组时或在程序的后面阶段进行. 定义一维数组的一般格式 ...
- my share
网盘一: username:3a1bd0f6634d72a0423aa21c7d2dee1a password:adaa0dfa36f537a4469fcc6e78823e1c 网盘二: userna ...
- 事件监听和window.history以及自定义创建事件
1.事件监听window.addEventListener方法: Window.addEventListener(event, function, useCapture); useCapture:表示 ...
- tcl之控制流-switch
- 提高mysql性能(like搜索替换 )
一 .mysql用find_in_set代替like搜索提高性能 SELECT * from mobantestinfo1 where find_in_set('33',info2); 二 .使用内部 ...
- POJ 1222 反转
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12469 Accepted: 7 ...
- BurpSuite 的使用
最好用的抓包软件, 不只是抓包软件 IE/Chrome中设置代理的方法是, 打开Internet选项面板->连接->局域网设置->取消勾选的使用自动配置脚本->勾选为LAN使用 ...