zoukankan      html  css  js  c++  java
  • BZOJ1006: [HNOI2008]神奇的国度

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1006

    题解:这题应该是留的最久的一个坑了吧。。。今天终于A掉了。。。但还是没有完全理解的感觉。

    代码:

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<iostream>
     7 #include<vector>
     8 #include<map>
     9 #include<set>
    10 #include<queue>
    11 #include<string>
    12 #include<bitset>
    13 #define inf 1000000000
    14 #define maxn 2000000+5
    15 #define maxm 10000000
    16 #define eps 1e-10
    17 #define ll long long
    18 #define pa pair<int,int>
    19 #define for0(i,n) for(int i=0;i<=(n);i++)
    20 #define for1(i,n) for(int i=1;i<=(n);i++)
    21 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    22 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    23 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
    24 #define mod 1000000007
    25 #define lch k<<1,l,mid
    26 #define rch k<<1|1,mid+1,r
    27 using namespace std;
    28 inline int read()
    29 {
    30     int x=0,f=1;char ch=getchar();
    31     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    32     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    33     return x*f;
    34 }
    35 int n,m,tot,head[maxn],id[maxn],pos[maxn],v[maxn];
    36 priority_queue<pa>q;
    37 struct edge{int go,next;}e[maxn];
    38 inline void add(int x,int y)
    39 {
    40     e[++tot]=(edge){y,head[x]};head[x]=tot;
    41     e[++tot]=(edge){x,head[y]};head[y]=tot;
    42 }
    43 int main()
    44 {
    45     freopen("input.txt","r",stdin);
    46     freopen("output.txt","w",stdout);
    47     n=read();m=read();
    48     for1(i,m)add(read(),read());
    49     for1(i,n)q.push(pa(0,i));
    50     for3(i,n,1)
    51     {
    52         while(id[q.top().second])q.pop();
    53         int x=q.top().second;q.pop();
    54         for4(j,x)if(!id[y])q.push(pa(++v[y],y));
    55         id[x]=i;pos[i]=x;
    56     }
    57     int ans=1;
    58     for1(i,n)
    59     {
    60         int tmp=0;
    61         for4(j,i)if(id[y]>id[i])tmp++;
    62         ans=max(ans,tmp+1);
    63     }
    64     cout<<ans<<endl;
    65     return 0;
    66 }
    View Code
  • 相关阅读:
    memcached的PHP扩展之PECL/memcache与PECL/memcached区别
    SQL*PLUS SET变量
    Centos中安装memcached
    HP Unix常用命令
    phpmbstring
    安装memcache到CentOS(另附yum法)
    CF Educational Codeforces Round 57划水记
    [NOIP2018]旅行(数据加强版)(图论+基环树)
    JavaScript DOM高级程序设计
    应用程序权限设计
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/4417455.html
Copyright © 2011-2022 走看看