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

    bzoj1854:[Scoi2010]游戏

    Description

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

    Input

    输入的第一行是一个整数N,表示lxhgww拥有N种装备 接下来N行,是对这N种装备的描述,每行2个数字,表示第i种装备的2个属性值

    Output

    输出一行,包括1个数字,表示lxhgww最多能连续攻击的次数。

    Sample Input

    3
    1 2
    3 2
    4 5

    Sample Output

    2

    HINT

    【数据范围】
    对于30%的数据,保证N < =1000
    对于100%的数据,保证N < =1000000


    题解:

    大水的一眼题。

    跑二分图匹配....

    属性和编号两边....跑一边停止了就输出(记得用时间戳,不然应该会超时)


    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    inline int read()
    {
        int f=1,x=0;char ch;
        while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return f*x;
    }
    int chw[2110000],match[2110000];
    struct node
    {
        int x,y,next;
    }a[2110000];int len,last[2110000];
    int t;
    void ins(int x,int y)
    {
        len++;
        a[len].x=x;a[len].y=y;
        a[len].next=last[x];last[x]=len;
    }
    bool find_muniu(int x)
    {
        for(int k=last[x];k;k=a[k].next)
        {
            int y=a[k].y;
            if(chw[y]!=t)
            {
                chw[y]=t;
                if(match[y]==-1 || find_muniu(match[y]))
                {
                    match[y]=x;
                    return true;
                }
            }
        }
        return false;
        
    }
    int main()
    {
        len=0;memset(last,0,sizeof(last));
        int n=read();
        for(int i=1;i<=n;i++)
        {
            int x=read(),y=read();
            ins(x,i);ins(y,i);
        }
        memset(match,-1,sizeof(match));
        int ans=0;
        for(int i=1;i<=len;i++)
        {
            t++;
            if(!find_muniu(i))
            {
                printf("%d
    ",i-1);
                return 0;
            }
        }
        printf("%d
    ",n);
        return 0;
    }
  • 相关阅读:
    Intel CPU编号详解
    matplotlib(二)——matplotlib控制坐标轴第一个刻度到原点距离
    matplotlib(一)——matplotlib横轴坐标密集字符覆盖
    博客园定制页面(五)——使用自定义JS脚本(公告栏显示时间)
    PyCharm(二)——PyCharm打开本地项目不显示项目文件
    nohup命令
    URL是如何解析的
    Python 得到主机字节序
    Python 得到ISP地址
    亚马逊s3上传大文件Python
  • 原文地址:https://www.cnblogs.com/CHerish_OI/p/7859895.html
Copyright © 2011-2022 走看看