http://codevs.cn/problem/2347/

Solution

二分图板子

连边:i认识j并且j是在校有床 i→j+n

i有床i→i+n

还有就是找要在学校的人,1.有床不回2.没床的(一定来探望)

记录一下二分图最大匹配是否等于要在校的学生即可

福利数据

IN

2

12
0 1 1 0 1 1 1 0 1 0 0 1
1 1 0 1 1 1 1 1 0 1 1 1
0 0 0 1 1 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 1 0 0 1 0 0
1 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0
0 0 1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 1 0 0 0 0 0 0
0 1 0 0 0 1 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0 0 0 1 0
12
0 1 1 1 1 1 1 0 1 1 1 1
1 1 0 1 1 1 1 0 1 1 1 1
0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0
1 1 0 0 1 0 0 1 0 0 0 0
0 1 0 1 0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 1 1 0
0 0 0 0 0 0 0 0 0 0 0 1
0 0 1 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0
12
1 1 1 0 1 1 0 1 1 0 1 1
0 1 1 1 0 1 1 1 1 1 1 1
0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 1
0 0 0 0 1 0 1 0 1 1 0 0
0 0 0 1 0 0 0 0 1 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 1 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 1 0 0 0 0 1
0 0 0 1 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 0 0

OUT

T_T
T_T
^_^

Code

// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=100010;
const int MAXM=100010;
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
struct Hungarian_dfs{
static const int N=110;
int cnt,n;
int match[N],a[N],c[N];
vector<int>b[N];int f[N];
inline void add(int u,int v){b[u].push_back(v);}
bool dfs(int x){
if(f[x]==cnt)return 0;
int num=b[x].size();f[x]=cnt;
for(int i=0;i<num;i++){
int nex=b[x][i];
if(match[nex]==-1||dfs(match[nex])){
match[x]=nex;match[nex]=x;return 1;
}
}
return 0;
}
void Work(){
int T=gi();
while(T--){
n=gi();int now=0;
for(int i=1;i<=n;i++)a[i]=gi(),b[i].clear();
for(int i=1;i<=n;i++){
c[i]=gi()?a[i]:0;
if(!c[i])now++;
if(a[i])add(i,i+n);
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(gi()&&a[j])add(i,j+n);//gi()放前面 逻辑短路
memset(f,false,sizeof(f));int ans=0;
for(int i=1;i<N;i++)match[i]=-1;
for(int i=1;i<=n;i++)
if(match[i]==-1&&!c[i]){
++cnt;if(dfs(i))++ans;else break;
}
printf(ans==now?"^_^\n":"T_T\n");
}
}
}d;
int main()
{
freopen("2347.in","r",stdin);
freopen("2347.out","w",stdout);
d.Work();
return 0;
}

  

【ZJOI2009】【Codevs 2347】假期的宿舍的更多相关文章

  1. BZOJ1433 ZJOI2009 假期的宿舍 二分图匹配

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2375  Solved: 1005[Submit][Sta ...

  2. 2055 [ZJOI2009]假期的宿舍

    P2055 [ZJOI2009]假期的宿舍 题目描述 学校放假了 · · · · · · 有些同学回家了,而有些同学则有以前的好朋友来探访,那么住宿就是一个问题.比如 A 和 B 都是学校的学生,A ...

  3. bzoj1433: [ZJOI2009]假期的宿舍

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2286  Solved: 969[Submit][Stat ...

  4. bzoj1433:[ZJOI2009]假期的宿舍

    明显的二分图最大匹配. #include<cstdio> #include<cstring> #include<cctype> #include<algori ...

  5. bzoj1433 [ZJOI2009]假期的宿舍(最大流)

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1717  Solved: 754[Submit][Stat ...

  6. BZOJ_1433_[ZJOI2009]假期的宿舍_二分图匹配

    BZOJ_1433_[ZJOI2009]假期的宿舍_二分图匹配 题意: 学校放假了······有些同学回家了,而有些同学则有以前的好朋友来探访,那么住宿就是一个问题.比如A 和B都是学校的学生,A要回 ...

  7. 1433: [ZJOI2009]假期的宿舍

    1433: [ZJOI2009]假期的宿舍 链接 分析: 直接网络流,看是否满足即可. S向每个有需要的人连边,有床的向T连边,认识的人之间互相连边. 代码: #include<cstdio&g ...

  8. bzoj 1433: [ZJOI2009]假期的宿舍 -- 最大流

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MB Description Input Output Sample Input ...

  9. bzoj 1433: [ZJOI2009]假期的宿舍

    1433: [ZJOI2009]假期的宿舍 Description Input Output Sample Input 1 3 1 1 0 0 1 0 0 1 1 1 0 0 1 0 0 Sample ...

  10. 洛谷P2055 [ZJOI2009]假期的宿舍

    P2055 [ZJOI2009]假期的宿舍 题目描述 学校放假了 · · · · · · 有些同学回家了,而有些同学则有以前的好朋友来探访,那么住宿就是一个问题.比如 A 和 B 都是学校的学生,A ...

随机推荐

  1. Linux网络配置出现的问题

    网络连接 : 选择桥接模式进入字符界面后,管理员登入后  ifconfig显示eth0和ol,但是不显示静态IP地址,即无inet.地址.广播.掩码 解决方案: 1.使用sudo dhclient e ...

  2. Python 1-2模块的循环导入问题

    run.py文件: import m1 # 第一次导入 # 验证解决方案一: ''' 正在导入m1 正在导入m2 ''' # print(m1.x) # print(m1.y) # 验证解决方案二: ...

  3. linux arp-显示和修改IP到MAC转换表

    博主推荐:更多网络测试相关命令关注 网络测试  收藏linux命令大全 arp命令用于操作主机的arp缓冲区,它可以显示arp缓冲区中的所有条目.删除指定的条目或者添加静态的ip地址与MAC地址对应关 ...

  4. Ubuntu系统搭建django+nginx+uwsgi

    1. 在开发机上的准备工作 2. 在服务器上的准备工作 3.安装uwsgi 4.编写uwsgi配置文件,使用配置文件启动uwsgi 5. 安装nginx 6. 收集静态文件 7. 编写nginx配置文 ...

  5. 简单的python代码实现语音朗读

    昨天女友生日,因为她一直对生日无感,所以我也就没有准备什么礼物.想起元旦前写的自动测试的脚本,添加了语音来提示测试和报告错误.灵机一动,为什么不用这个语音来庆祝她生日快乐呢?身为设计公司市场经理的她对 ...

  6. JS 根据参数是否为空进行true|false判断呢

    <form id="actForm" action="${ctx}/meeting/vip/saveMeetingAttendVipAct" method ...

  7. Git 与其他系统 - Git 与 Subversion

    https://git-scm.com/book/zh/v1/Git-%E4%B8%8E%E5%85%B6%E4%BB%96%E7%B3%BB%E7%BB%9F-Git-%E4%B8%8E-Subve ...

  8. [K/3Cloud] 分录行复制和新增行的冲突如何处理

    新增行:执行AfterCreateNewEntryRow,这个函数里面对一些数据进行处理(比如字段给上默认值): 复制行:复制行过程中希望这些字段能够得到我修改行信息后的数据,如果不处理,执行到Aft ...

  9. 解方程(codevs 3732)

    题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .i ...

  10. ELK pipeline

    https://www.felayman.com/articles/2017/11/24/1511527532643.html?utm_medium=hao.caibaojian.com&ut ...