zoukankan      html  css  js  c++  java
  • BZOJ1854: [Scoi2010]游戏

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1854

    题目大意:lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示。当他使用某种装备时,他只能使用该装备               的某一个属性。并且每种装备最多只能使用一次。 游戏进行到最后,lxhgww遇到了终极boss,这个终极boss很奇怪,攻击他的装备所使用的属性值必须从1开始连续递增               地攻击,才能对boss产生伤害。也就是说一开始的时候,lxhgww只能使用某个属性值为1的装备攻击boss,然后只能使用某个属性值为2的装备攻击boss,然后只能使用                 某个属性值为3的装备攻击boss……以此类推。 现在lxhgww想知道他最多能连续攻击boss多少次?

    题解:好题啊,竟然可以写并查集,然而我知道写二分图最大匹配,但是脑补+看题解,我还是选择了神奇的并查集写法-------

       详见:http://hzwer.com/2950.html

    代码:

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<cstdio>
     5 #include<algorithm>
     6 #define N 1000005
     7 using namespace std;
     8 int n,a,b;
     9 int fa[N];
    10 bool vis[N];
    11 int read()
    12 {
    13     int x=0; char ch; bool bo=0;
    14     while (ch=getchar(),ch<'0'||ch>'9') if (ch=='-') bo=1;
    15     while (x=x*10+ch-'0',ch=getchar(),ch>='0'&&ch<='9');
    16     if (bo) return -x; return x;
    17 }
    18 int find(int x)
    19 {
    20     if (fa[x]!=x) fa[x]=find(fa[x]);
    21     return (fa[x]);
    22 }
    23 int main()
    24 {
    25     n=read();
    26     for (int i=1; i<=n+1; i++) fa[i]=i;
    27     for (int i=1; i<=n; i++)
    28     {
    29         a=read(),b=read();
    30         int q=find(a),p=find(b);
    31         if (q==p)
    32         {
    33             vis[p]=true; 
    34         }
    35         else 
    36         {
    37             if (q<p) swap(q,p);
    38             vis[p]=true; fa[p]=q;
    39         }
    40     }
    41     int i;
    42     for (i=1; i<=n+1; i++) if (!vis[i]) break;
    43     printf("%d
    ",i-1);
    44 }
    View Code
  • 相关阅读:
    开启ecstore隐藏的功能
    对接ECOS框架(含ecstore、ocs、erp等产品)的方法【其他系统请求ecos的api接口】
    shopex 网店系统基于云登录系统的信任登录设置
    怎样获取机器码
    windows 无法连接远程桌面
    ecos框架中data/ 目录下img*文件数量过多的问题
    mac 下brew解决php安装问题
    20140708 总结
    20140705 总结
    bzoj 2751
  • 原文地址:https://www.cnblogs.com/HQHQ/p/5612360.html
Copyright © 2011-2022 走看看