[NOI 2010]航空管制
Description
Input
Output
由两行组成。
第一行包含 n个整数,表示一个可行的起飞序列,相邻两个整数用空格分隔。
输入数据保证至少存在一个可行的起飞序列。如果存在多个可行的方案,输出任意一个即可。
第二行包含 n个整数 t1, t2, „, tn,其中 ti表示航班i可能的最小起飞序号,相邻两个整数用空格分隔。
Sample Input
4 5 2 5 4
1 2
3 2
5 1
3 4
3 1
Sample Output
3 4 1 2 1
题解(转载)
正解:贪心+堆。
第一问很简单,反向拓扑序+大根堆,然后从后往前依次填序号就行。
第二问其实也不难。和第一问一样,只要我们把当前这个点卡住,不对它进行任何操作,当我们发现堆中取出的点没有办法再标号时,那这个标号就是询问点的最小标号。
(luogu大牛分站开O2可以过)
//It is made by Awson on 2017.11.1
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
using namespace std;
const int N = ;
const int M = ; int n, m, u, v;
int k[N+], kp[N+];
struct tt {
int to, next;
}edge[M+];
int path[N+], top;
int ans[N+];
struct node {
int x, k;
node() {
}
node (int _x, int _k) {
x = _x; k = _k;
}
bool operator < (const node &b) const {
return k < b.k;
}
}; priority_queue<node>Q;
int in[N+]; void add(int u, int v) {
edge[++top].to = v;
edge[top].next = path[u];
path[u] = top;
}
void topsort(int lim) {
while (!Q.empty()) Q.pop();
for (int i = ; i <= n; i++) {
in[i] = kp[i];
if (kp[i] == && i != lim) Q.push(node(i, k[i]));
}
for (int cnt = n; cnt >= ; cnt--) {
if (Q.empty()) {
printf("%d ", cnt); return;
}
if (Q.top().k < cnt) {
printf("%d ", cnt); return;
}
ans[cnt] = Q.top().x; Q.pop();
for (int i = path[ans[cnt]]; i; i= edge[i].next) {
in[edge[i].to]--;
if (in[edge[i].to] == ) {
if (edge[i].to != lim) Q.push(node(edge[i].to, k[edge[i].to]));
}
}
}
}
void work() {
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++) scanf("%d", &k[i]);
for (int i = ; i <= m; i++) {
scanf("%d%d", &u, &v); add(v, u); kp[u]++;
}
topsort();
for (int i = ; i <= n; i++) printf("%d ", ans[i]);
printf("\n");
for (int i = ; i <= n; i++) topsort(i);
}
int main() {
work();
return ;
}
[NOI 2010]航空管制的更多相关文章
- BZOJ 2535:NOI 2010 航空管制
[NOI2010]航空管制 题面请点上面. 首先第一问,我第一想法是把它放到一个小根堆中,然而这是不行的. 正确的思路是,把图反过来建,然后放到一个大根堆里去. 至于原因,感性理解一下,正着贪是有后效 ...
- 解题:NOI 2010 航空管制
题面 常见的套路与不常见的套路 第一问是常见的套路,建反边用优先队列跑拓扑排序 第二问是不常见的套路,如何判断一个点最早什么时候起飞?先不加它来拓扑排序,直到拓扑排序不能进行下去了,这个时刻就是它必须 ...
- BZOJ2109: [Noi2010]Plane 航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...
- BZOJ2535 [Noi2010]Plane 航空管制2
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...
- 2109&2535: [Noi2010]Plane 航空管制 - BZOJ
Description世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上, ...
- NOI2010航空管制
2008: [Noi2010]航空管制 Time Limit: 10 Sec Memory Limit: 552 MBSubmit: 31 Solved: 0[Submit][Status] De ...
- bzoj 2109: [Noi2010]Plane 航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...
- bzoj2535 [Noi2010]航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...
- [NOI2010]航空管制(拓扑排序+贪心)
题目描述 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上,小X不幸又一 ...
随机推荐
- 201621123050 《Java程序设计》第9周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 ①foreach循环 for (String e : map.keyS ...
- Flask jinja2 全局函数,宏
内置全局函数 dict()函数,方便生成字典型变量 {% set user = dict(name='Mike',age=15) %} <p>{{ user | tojson | safe ...
- python使用tesseract-ocr完成验证码识别(安装部分)
一.tesseract-ocr安装 Ubuntu版本: 1.tesseract-ocr安装 sudo apt-get install tesseract-ocr 2.pytesseract安装 sud ...
- Java中Math类的常用方法
public class MathDemo { public static void main(String args[]){ /** * abs求绝对值 */ System.out.println( ...
- LeetCode & Q28-Implement strStr-Easy
String Two Pointers Description: Implement strStr(). Returns the index of the first occurrence of ne ...
- 有货前端 Web-APM 实践
有货前端 Web-APM 实践 0 背景 有货电商技术架构上采用的是前后端分离,前端是主要以业务展示和接口聚合为主,拥有自己的 BFF (Backend For Frontend),以 nodejs ...
- 算法题丨Two Sum
描述 Given an array of integers, return indices of the two numbers such that they add up to a specific ...
- 帧动画的创建方式 - xml方式
废话不多说,先看东西 创建帧动画1 - xml方式 帧动画的创建方式主要以下2种: * 用xml创建动画: * 用代码创建动画: 本文内容主要关注 xml文件 创建帧动画的方式 xml文件 ...
- gradle入门(1-8)gradle 的依赖查看、依赖排除和指定版本(需要验证!)
一.依赖查看 gradle dependencies 在gradle dependencies输出会有如下几种标记: 1.版本 : 唯一的依赖. 2.版本():还存在该库其他版本的依赖或者间接依赖,并 ...
- python jquery
jquery 一.寻找元素(选择器和筛选器) a.选择器 1.基本选择器 1 $("*") $("#id") $(".class") ...