Swap——hdu 2819
Swap
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2152 Accepted Submission(s): 764
Special Judge
If it is impossible to make all the diagonal entries equal to 1, output only one one containing “-1”.
R 1 2
-1
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; #define N 1100 int n, vis[N], used[N], a[N], b[N];
int maps[N][N]; int found(int u)
{
for(int i = ; i <= n; i++)
{
if(!vis[i] && maps[u][i])
{
vis[i] = ;
if(!used[i] || found(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
}
int main()
{
int w; while(scanf("%d", &n) != EOF)
{
memset(vis, , sizeof(vis));
memset(used, , sizeof(used));
memset(maps, , sizeof(used));
memset(a, , sizeof(a));
memset(b, , sizeof(b)); int ans = ; for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
scanf("%d", &maps[i][j]); for(int i = ; i <= n; i++)
{
memset(vis, , sizeof(vis));
if(found(i))
ans++;
}
if(ans < n)
{
printf("-1\n");
continue;
} w = ;
for(int i = ; i <= n; i++)
{
while(used[i] != i)
{
a[w] = i;
b[w] = used[i];
swap(used[a[w]], used[b[w]]); // 如果该行匹配不是自身,就交换匹配。
w++;
}
}
printf("%d\n", w);
for(int i = ; i < w; i++)
printf("C %d %d\n", a[i], b[i]); }
return ;
}
Swap——hdu 2819的更多相关文章
- Swap HDU - 2819 (有关矩阵的二分匹配)
题意见大佬:https://www.cnblogs.com/gj-Acit/archive/2013/08/17/3265502.html 题目大意很明确,交换图的某些行或者是某些列(可以都换),使得 ...
- E - Swap - hdu 2819(简单二分图匹配)
题意:如果可以交换行列,问主对角线能不能全为1 分析:要想主对角线全为1很明显要有N个行列不想同的点就行了,可以用二分图匹配计算出来多能有几个.如果小与N就不能.输出要是对的就行,不必和答案一样 ** ...
- HDU 2819 ——Swap——————【最大匹配、利用linker数组、邻接表方式】
Swap Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- hdu 2819 Swap
Swap http://acm.hdu.edu.cn/showproblem.php?pid=2819 Special Judge Problem Description Given an N*N m ...
- HDU 2819 Swap(行列式性质+最大匹配)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2819 题目大意:给你一个n*n的01矩阵,问是否可以通过任意交换整行或者整列使得正对角线上都是1. ...
- HDU 2819 Swap(二分图匹配)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2819 [题目大意] 给出一个棋盘,由白格子和黑格子组成,可以交换棋盘的行列, 使得其主对角线为黑格 ...
- HDU 2819 — Swap 二分匹配
Swap Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU - 2819 Swap(二分图最大匹配)
Given an N*N matrix with each entry equal to 0 or 1. You can swap any two rows or any two columns. C ...
- HDU 2819 - Swap - [二分图建模+最大匹配]
题目链接:https://cn.vjudge.net/problem/HDU-2819 Given an N*N matrix with each entry equal to 0 or 1. You ...
随机推荐
- altium笔记转载
原理图的设计 1.左键单击元器件按住space键可以将其旋转,按X键左右旋转:按Y键上下旋转. 2.智能粘贴:Edit àsmart paste . 3.屏障:compile mask(编译时被屏障的 ...
- Jmeter之Json表达式关联
Jmeter使用中,通常用的最多的是正则表达式和Xpath表达式,但是现在大多数网站都用的Json返回数据,而且数据还特长的那种,作为合格的测试人员也要适应技术潮流发展,下面介绍利用Json Extr ...
- dvorak键盘布局调整
一站直达: http://www.kaufmann.no/roland/dvorak/
- Linq查询语法(1)
转:http://www.cnblogs.com/ahao214/archive/2013/01/22/2871044.html LINQ的基本格式如下所示:var <变量> = from ...
- Windows 10更新后无法启动Dolby音频驱动程序
在电脑更新Windows 10 1903版本后,重启出现如下问题: 经查,这与驱动强制签名有关.解决方法如下: 打开"设置"->"更新与安全"->& ...
- 解决MarkDown打开出现:awesomium web-brower framework This view has crashed
当在windows 8 以上操作系统安装markdown 的时候,可能会出现这样的错误 解决方法: 官网链接:http://markdownpad.com/faq.html#livepreview-d ...
- BZOJ 1767] [Ceoi2009] harbingers (斜率优化)
[BZOJ 1767] [Ceoi2009] harbingers (斜率优化) 题面 给定一颗树,树中每个结点有一个邮递员,每个邮递员要沿着唯一的路径走向capital(1号结点),每到一个城市他可 ...
- 通过离线安装包解决了 from cryptography.hazmat.bindings._openssl import ffi, lib ImportError: /usr/local/python36/lib/python3.6/site-packages/cryptography-2.2.2-py3.6-linux-x86_64.egg/cryptography/hazmat/binding
场景:内网服务器不能上外网(代理也不通!), 之前安装了PYTHON的几个安装包,但不是知道为什么无法使用PARAMIKO这个模块 在导入 from cryptography.hazmat.bindi ...
- 不想用ubuntu了,换个系统manjaro - change
# 下载 https://mirrors.tuna.tsinghua.edu.cn/osdn/storage/g/m/ma/manjaro/xfce/ # usb启动盘 rufus # 中文字体 pa ...
- QTextStream写文件中文乱码解决办法
1.首先把Qt Creator的编辑器设置为使用 UTF-8: 工具-->选项-->文本编辑器-->行为,在右侧选项界面找到文件编码选项,设置为 UTF-8.2.使用 QText ...