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的更多相关文章

  1. 2109&2535: [Noi2010]Plane 航空管制 - BZOJ

    Description世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上, ...

  2. BZOJ 2535: [Noi2010]Plane 航空管制2

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...

  3. bzoj 2109: [Noi2010]Plane 航空管制

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...

  4. BZOJ2109: [Noi2010]Plane 航空管制

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...

  5. BZOJ2535 [Noi2010]Plane 航空管制2

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此,小X表示很不满意. 在这次来烟台的路上 ...

  6. [BZOJ2109]Plane 航空管制

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...

  7. bzoj 2535 && bzoj 2109 [Noi2010]Plane 航空管制——贪心

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2535 https://www.lydsy.com/JudgeOnline/problem.p ...

  8. bzoj 2535: [Noi2010]Plane 航空管制2【拓扑排序+堆】

    有个容易混的概念就是第一问的答案不是k[i]字典序最小即可,是要求k[i]大的尽量靠后,因为这里前面选的时候是对后面有影响的(比如两条链a->b c->d,ka=4,kb=2,kc=3,k ...

  9. BZOJ.2109.[NOI2010]航空管制(拓扑 贪心)

    题目链接 双倍经验(没有第一问) \(Description\) \(Solution\) 第一问拓扑排序即可. 第二问,即让一个元素在拓扑序中尽量靠前,好像不好做. 但是可以让一个元素出现尽量靠后. ...

随机推荐

  1. (转)centos6起/etc/syslog.conf不再有!而是/etc/rsyslog.conf代替!

    centos6起/etc/syslog.conf不再有!而是/etc/rsyslog.conf代替!

  2. Android使用xml中定义的动画效果

    Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.zqrl_out); animation.setFil ...

  3. XML基础<第一篇>

    一.XML简介 XML是一种标记语言,用于描述数据,它提供一种标准化的方式来来表示文本数据.XML文档以.xml为后缀.需要彻底注意的是XML是区分大小写的. 先从一个简单的XML例子来了解下xml基 ...

  4. 关于在C#中实现AOP 拦截编程模式的新的探索

    前面有篇文章,是从其他个人博客中贴过来的.地址:http://www.lanhusoft.com/Article/240.html 作者总结实现的挺好. 但是.不能不考虑性能!!使用 ContextB ...

  5. Android的init过程详解(一)(转)

    本文使用的软件版本 Android:4.2.2 Linux内核:3.1.10 本文及后续几篇文章将对Android的初始化(init)过程进行详细地.剥丝抽茧式地分析,并且在其中穿插了大量的知识,希望 ...

  6. c++ 05

    一.单例模式 二.成员指针 class Student { public:   string m_name;   void print (void) { ... } }; 1.指向成员变量的指针 成员 ...

  7. Sqrt(x) 解答

    Question Implement int sqrt(int x). Compute and return the square root of x. Solution 1 -- O(log n) ...

  8. oracle 12g sqlplus安装

    一.下载oracle 12g sqlplus软件 linux 64位操作系统,oracle安装包地址 http://www.oracle.com/technetwork/topics/linuxx86 ...

  9. VIm变成sublime (转)

    sublime在ubuntu下始终支持不是很好, 特别是对中文输入的支持,还有一些插件在ubuntu下也不能用. 在ubuntu下还是用vim吧.  我们一起把vim变成sublime. 只需要三步 ...

  10. python之路-模块 splinter

    Splinter介绍 Splinter is an open source tool for testing web applications using Python. It lets you au ...