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\) 第一问拓扑排序即可. 第二问,即让一个元素在拓扑序中尽量靠前,好像不好做. 但是可以让一个元素出现尽量靠后. ...
随机推荐
- Resharper 7小技巧系列:导航、书签、和最近编辑
原文 http://www.cnblogs.com/feichexia/archive/2012/09/21/resharper_tricks_part1.html 先上一张花了一个多小时画的Resh ...
- 在 Azure 虚拟机上部署反恶意软件解决方案
本博客文章由我和我的同事 Sung Hsueh 共同撰写,Sung Hsueh 是 Microsoft Azure 计算部负责安全事项的项目经理. 本博客文章为"虚拟机扩展程序"系 ...
- haproxy简单负载均衡搭建
最近对负载均衡进行搭建具体方法如下: haproxy 修改部分(haproxy-cfg.cfg) global daemon maxconn 4500 defaults mode http timeo ...
- 去掉java反编译(JD-GUI)生成的源文件中注释
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...
- unix c 11
多线程(thread) 操作系统支持多进程,进程内部使用多线程. 进程是 重量级的,拥有自己 独立的内存空间. 线程是 轻量级的,不需要拥有自己 独立的内存空间,线程的内存空间:1 ...
- Uninstall or Disable Java on a Mac
You can run Java apps in two ways. The first is to run Java applets inside your Web browser with a p ...
- poj1703--Find them, Catch them(并查集应用)
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32073 Accepted: ...
- 怎么实现类似星星闪烁的效果(box-shadow)
有时候设计希望我们能够在页面实现类似星星闪烁的效果,如图: 我的解决办法是用box-shadow: html <div class="star04 active-blink" ...
- 我的第一个MVC项目
这是本人第一个完全按照MVC开发模式完成的项目,非常简陋,仅仅完成的查询,保存,删除基本功能,而且存在编码问题没有解决,以后会慢慢增加功能.慢慢改进 package com.sdjt.dao; imp ...
- 0118——UIButtton
1.Button的定义 UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; Button有六种类型 enum { UI ...