BZOJ 2535 Plane 航空管制2
http://www.lydsy.com/JudgeOnline/problem.php?id=2535
思路:对于1,我们只需要每个点比前驱大就可以了,然后满足尽量优。
对于第二问,我们先求出这个点前驱有几个,记为ans,cnt=ans
每访问一个未访问的点,cnt++
然后对于后面的点从少往大排,若有k>ans,那么一定在我们当前处理这个点前面,ans++
若有k<=cnt,说明要i放在这个点的后面,因此ans=k+1
记得不要省方便add(read(),read()),好像会出错。
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
struct node{
int k,id;
}p[];
int tot=,go[],next[],first[];
int A[],n,m,vis[],cnt;
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void insert(int x,int y){
tot++;
go[tot]=y;
next[tot]=first[x];
first[x]=tot;
}
void add(int x,int y){
insert(x,y);insert(y,x);
}
void init(){
n=read();m=read();
for (int i=;i<=n;i++) p[i].k=read(),p[i].id=i;
for (int i=;i<=m;i++){
int x=read(),y=read();
add(x,y);
}
}
bool cmp(node q,node w){
return q.k<w.k;
}
bool deal(int x){
for (int i=first[x];i;i=next[i]){
if (i&){
int pur=go[i];
p[x].k=std::min(p[x].k,p[pur].k-);
}
}
}
void solve1(){
for (int j=;j<=n;j++)
for (int i=;i<=n;i++)
deal(i);
std::sort(p+,p++n,cmp);
for (int i=;i<n;i++) printf("%d ",p[i].id);
printf("%d\n",p[n].id);
}
int count(int x){
int res=;vis[x]=;
for (int i=first[x];i;i=next[i]){
int pur=go[i];
if (!vis[pur]&&(i%==)){
res+=count(pur);
}
}
return res+;
}
void solve2(){
for (int i=;i<=n;i++){
memset(vis,,sizeof vis);
int ans=count(i);
cnt=ans;
for (int j=;j<=n;j++)
if (!vis[p[j].id]){
cnt++;
if (p[j].k<=ans) ans++;
else if (cnt>p[j].k) ans=p[j].k+;
}
A[i]=ans;
}
for (int i=;i<n;i++) printf("%d ",A[i]);
printf("%d\n",A[n]);
}
void work(){
solve1();
solve2();
}
int main(){
init();
work();
}
BZOJ 2535 Plane 航空管制2的更多相关文章
- 2109&2535: [Noi2010]Plane 航空管制 - BZOJ
Description世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上, ...
- BZOJ 2535: [Noi2010]Plane 航空管制2
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...
- bzoj 2109: [Noi2010]Plane 航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...
- BZOJ2109: [Noi2010]Plane 航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...
- BZOJ2535 [Noi2010]Plane 航空管制2
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...
- [BZOJ2109]Plane 航空管制
Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...
- bzoj 2535 && bzoj 2109 [Noi2010]Plane 航空管制——贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2535 https://www.lydsy.com/JudgeOnline/problem.p ...
- bzoj 2535: [Noi2010]Plane 航空管制2【拓扑排序+堆】
有个容易混的概念就是第一问的答案不是k[i]字典序最小即可,是要求k[i]大的尽量靠后,因为这里前面选的时候是对后面有影响的(比如两条链a->b c->d,ka=4,kb=2,kc=3,k ...
- BZOJ.2109.[NOI2010]航空管制(拓扑 贪心)
题目链接 双倍经验(没有第一问) \(Description\) \(Solution\) 第一问拓扑排序即可. 第二问,即让一个元素在拓扑序中尽量靠前,好像不好做. 但是可以让一个元素出现尽量靠后. ...
随机推荐
- ASP.NET MVC3快速入门——第四节、添加一个模型
在本节中我们将追加一些类来管理数据库中的电影.这些类将成为我们的MVC应用程序中的“模型”部分.我们将使用一个.NET Framework的被称之为“Entiry Framework”的数据访问技术来 ...
- 修改和获取web.config或app.config文件appSettings配置节中的Add里的value属性 函数
1: /// <summary> 2: /// 修改web.config或app.config文件appSettings配置节中的Add里的value属性 3: /// </summ ...
- 《Algorithms 4th Edition》读书笔记——3.1 符号表(Elementary Symbol Tables)-Ⅰ
3.1符号表 符号表最主要的目的就是将一个键和一个值联系起来.用例能够将一个键值对插入符号表并希望在之后能够从符号表的所有键值对中按照键值姐找到对应的值.要实现符号表,我们首先要定义其背后的数据结构, ...
- Jquery radio checked
Jquery radio checked radio 1. $("input[name='radio_name'][checked]").val(); //选择被选中Rad ...
- Smart ——jiaoyou模板
<!--{foreach $vip_data as $key=>$volist}--> <!--{if $key==0 ||$key==1||$key==5||$key= ...
- qt model/view 架构自定义模型之QStringListModel
# -*- coding: utf-8 -*- # python:2.x #QStringListModel #QStringListModel 是最简单的模型类,具备向视图提供字符串数据的能力. # ...
- STS(Spring Tool Suite)使用前准备
sts 的基础框架拿的eclipse的,你可以理解为eclipse + spring插件的高级升华版.在使用上可以很大限度的参考eclipse的操作. 首先,调整字体. 中文很麻烦的,因为编码问题.习 ...
- 关于safari上的select宽高问题小技,自定义下拉框
之前一直用windows做开发,最近换了个mac,在几经折腾之下,安装完了各种开发工具,IDE等,然后欣然打开自己正在开发的网站.突然发现mac上所有的下拉框都变了,都是默认样式,无论padding, ...
- HDU 4362 Dragon Ball 线段树
#include <cstdio> #include <cstring> #include <cmath> #include <queue> #incl ...
- 利用jquery来隐藏input type="file"
<li> <input type="text" name="token" value = "<?php ech$_SESSIO ...