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\) 第一问拓扑排序即可. 第二问,即让一个元素在拓扑序中尽量靠前,好像不好做. 但是可以让一个元素出现尽量靠后. ...
随机推荐
- SSL和SSH和OpenSSH,OpenSSL有什么区别
ssl是通讯链路的附加层.可以包含很多协议.https, ftps, ..... ssh只是加密的shell,最初是用来替代telnet的.通过port forward,也可以让其他协议通过ssh的隧 ...
- 匹配“is outside location”
<pre name="code" class="html">is outside location 怎么匹配? . 匹配除换行外的所有单个字符,通常 ...
- mysqli connect database and print
<?php $connect = mysqli_connect('localhost','root','','intertrading') or die('Unale to connect'); ...
- < welcome > 一起学习,进步,分享。
现在时间:2014-3-24 hello world my blog. 第一次做博客,欢迎各路朋友指教.慢慢的分享学习到得东西,本人目前正在做IOS,也在学习数据库简单地应用. 作为一个IOS开发者, ...
- debian下编译libev库
系统为Linux debian 2.6.32-5-686.这是裸系统,连xwindows都没有.帐户为root,不是的注意一下权限.这里想说明安装过程及出现的问题,故打印的信息较多,以供出现错误的读者 ...
- pyqt动态创建一系列组件并绑定信号和槽(网友提供学习)
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #如上图要求:创建指定多个复选框,一种是通过QT设计器Designe ...
- Top 15 Tools To Make Animated GIFs From Images & Video
Creating an animated GIF picture from photos or video with Adobe Photoshop is easy, but not everyone ...
- 浅谈Android系统开发中LOG的使用
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6581828 在程序开发过程中,LOG是广泛使用 ...
- 修改tomcat访问路径
<Context path="/pc" docBase="/data/www/8084/kabao-pc-consume/" reloadable=&qu ...
- [跟我学spring学习笔记][更多DI知识]
延迟初始化Bean 定义: 延迟初始化也叫做惰性初始化,指不提前初始化Bean,在真正使用时才创建并初始化Bean 如何延迟: 配置方式很简单只需在标签上指定 “lazy-init” 属性值为“tru ...