首页 > 其他分享 >P1894 [USACO4.2] 完美的牛栏The Perfect Stall

P1894 [USACO4.2] 完美的牛栏The Perfect Stall

时间:2024-03-06 21:37:39浏览次数:28  
标签:Perfect 滚蛋 int P1894 belong vis Stall 位子 &&

原题链接

题解

二分图匹配,总的来说就是如果我的位子没人霸占,那我就坐,如果没人霸占,那我尝试着让他滚蛋
如果一个位子经历过两次滚蛋,说明别人确实没位子坐了,人家确实需要这个位子,那我就换一个位子

code

#include<bits/stdc++.h>
using namespace std;
int belong[205]={0};
int vis[205]={0};
vector<int> G[205];
int ss(int now)//这个函数的定义为搜索当前节点能否找到归属
{
    for(auto to:G[now]) if((!belong[to]||(!vis[to]&&(vis[to]=1)&&ss(belong[to])))&&(belong[to]=now)) return 1;//用&&完成赋值
    //如果这个点没有被滚蛋过,那就访问这个点,让他滚蛋,或者是这个点还没有人踏足过
    return 0;
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        int k;
        cin>>k;
        while(k--)
        {
            int x;
            cin>>x;
            G[i].push_back(x);
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        memset(vis,0,sizeof vis);//记录牛棚的访问情况,如果塞入当前节点的时候牛棚访问超过两次,说明出现循环调用,而这时调用这个点的可以是任何点
        sum+=ss(i);
    }
    cout<<sum<<endl;
    return 0;
}

标签:Perfect,滚蛋,int,P1894,belong,vis,Stall,位子,&&
From: https://www.cnblogs.com/pure4knowledge/p/18057627

相关文章

  • /usr/bin/install: 无法更改“/usr/local/python397/bin“ 的权限: 没有那个文件或目
    /usr/bin/install:无法更改“/usr/local/python397/bin“的权限:没有那个文件或目录dragoo1于2021-09-2116:39:21发布阅读量3.7k收藏9点赞数4分类专栏:python文章标签:pythoninstall没有那个文件或目录版权python专栏收录该内容3篇文章0订阅订阅专栏编译python......
  • 未完成编辑 Linux CentOS7.6使用腾讯Yum源安装MySQL5.7,执行mysql-secure-installation
    学习安装MySQL时发现官方源很慢,试了国内腾讯源快,记录一下LinuxCentOS7.6前置环境:CPU1内存4GB硬盘SCSI20GB网络模式桥接系统内为自动DHCPpingqq.com可通互联网以下为MySQL5.7安装步骤编辑新repo库路径:/etc/yum.repos.d/mysql-community.repovi/etc/yum.repos......
  • pip install selenium报错 raise ReadTimeoutError--解决方法
    pipinstallselenium报错如下:raiseReadTimeoutError(self._pool,None,"Readtimedout.")pip._vendor.urllib3.exceptions.ReadTimeoutError:HTTPSConnectionPool(host='files.pythonhosted.org',port=443):Readtimedout. 原因:timeout超时,默认15s解......
  • pip:pip install时拒绝访问
    1、背景在公司的内网电脑上,使用pipinstall报错拒绝访问。根据网上查到的经验,要么是以管理员方式运行cmd,要么是在pip指令后加target参数修改安装路径,但是这两种方式都无法起效果。在cmd中输入wherepipwherepipd:\用户\xxx\Desktop\pypro\pip.exe可以看到pip指令实际上......
  • NPM install报错certificate has expired
    Installfail!Error:certificatehasexpiredError:certificatehasexpiredatTLSSocket.onConnectSecure(_tls_wrap.js:1515:34)atTLSSocket.emit(events.js:400:28)atTLSSocket._finishInit(_tls_wrap.js:937:8)atTLSWrap.ssl.onhandshakedone(_......
  • How to Create a Wimboot Installation of Windows 8.1(转载)
    HowtoCreateaWimbootInstallationofWindows8.1Introduction:HowtoCreateaWimbootInstallationofWindows8.1IntroductionEverwonderhowcomputermanufacturerscanfita20GBinstallationofWindowsontoa16GBdrive?Itisnowpossiblewith......
  • Windows ® Installer. V 5.0.20348.1668 (msiexec命令 参数
    Windows®Installer.V5.0.20348.1668msiexec/Option<RequiredParameter>[OptionalParameter]安装选项 </package|/i><Product.msi> 安装或配置产品 /a<Product.msi> 管理安装-在网络上安装产品 /j<u|m><Product.msi>[/t<TransformList>......
  • pip install 命令详解
    pipinstall命令用于安装Python包,支持从多种源安装包1.通过pipinstall-h命令查看帮助文档总共包括:1.usage2. Description3. InstallOptions4. PackageIndexOptions5. GeneralOptions: 1.用法(usage):Usage:pipinstall[options]<requirementspecifie......
  • 「ABC339C」 Perfect Bus
    题意有一辆公交车,路上会在\(N\)个站点停靠,每个站点会有\(A_i\)个乘客上下车(正数表示上车,负数表示下车)。请选择一个恰当的正整数作为起始时车上的人数,使得路途中乘客的人数总为非负数。然后输出最终车上的人数。分析从头到尾遍历一遍\(A\),计算总和\(s\),这是到达终点......
  • 记录pyinstaller 打包 pdfplumber 问题解决过程
    今天有一个pdf文件处理需求,使用pdfplumber库完成,python环境是3.11+win10pyinstaller5.10.1打包完成后,工具可以顺利打开,但是执行处理的时候报错File"pypdfium2_raw\bindings.py",line93,in<module>File"pypdfium2_raw\bindings.py",line83,in_register_library......