HDU 3360 National Treasures 奇偶匹配的最低点覆盖
标题来源: pid=3360">HDU 3360 National Treasures
意甲冠军:假设a[i][j] != -1 把他转成二进制 最多有12位 代表题目那张图的12个位置 假设相应位是1 说明在那里放一个守卫能够看住a[i][j]位置上的这个东西
思路:明显死最小点覆盖 奇偶匹配建图
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = 55;
int vis[maxn*maxn];
int y[maxn*maxn];
vector <int> G[maxn*maxn];
int n, m;
int a[maxn][maxn];
int dir[12][2] = {-1, -2, -2, -1, -2, 1, -1, 2, 1, 2, 2, 1, 2, -1, 1, -2, -1, 0, 0, 1, 1, 0, 0, -1};
bool dfs(int u)
{
for(int i = 0; i < G[u].size(); i++)
{
int v = G[u][i];
if(vis[v])
continue;
vis[v] = true;
if(y[v] == -1 || dfs(y[v]))
{
y[v] = u;
return true;
}
}
return false;
}
int match()
{
int ans = 0;
memset(y, -1, sizeof(y));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
if((i+j)%2)
{
memset(vis, 0, sizeof(vis));
if(dfs(i*m+j))
ans++;
}
}
}
return ans;
} int main()
{
int cas = 1;
while(scanf("%d %d", &n, &m) && (n||m))
{
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
scanf("%d", &a[i][j]);
for(int i = 0; i < n*m; i++)
G[i].clear();
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
int x = a[i][j];
if(x == -1)
continue;
for(int k = 0; k < 12; k++, x >>= 1)
{
if(!x)
break;
if(!(x&1))
continue; int xx = i + dir[k][0];
int yy = j + dir[k][1];
if(xx < 0 || xx >= n || yy < 0 || yy >= m)
continue;
if(a[xx][yy] == -1)
continue;
if((i+j)%2)
G[i*m+j].push_back(xx*m+yy);
else
G[xx*m+yy].push_back(i*m+j);
}
}
}
printf("%d. %d\n", cas++, match());
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
HDU 3360 National Treasures 奇偶匹配的最低点覆盖的更多相关文章
- HDU 3360 National Treasures(二分匹配,最小点覆盖)
National Treasures Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 3360 National Treasures(最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3360 题目大意: 在一个n*m的格子中,每个格子有一个数值,-1表示空,其余表示财宝.每个财宝的数值转 ...
- HDU 3360 National Treasures
题目大意:大厅每个位置都有一个文物或者一个守卫,文物是安全的前提是: 关键位置上必须有一个守卫,或者文物本身的位置上有一个守卫.求保证每个文物是安全的守卫的最少数量. #include <cst ...
- HDU 1083 网络流之二分图匹配
http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
- hdu 2255 二分图最大权匹配 *
题意:说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子.这可是一件大事,关系到人民的住房问题啊.村里共有n间房间,刚好有n家老百姓,考虑到每家都要有房住(如果有老百姓没房 ...
- HDU 1010 (DFS搜索+奇偶剪枝)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep&g ...
- HDU(1853),最小权匹配,KM
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1853 Cyclic Tour Time Limit: 1000/1000 MS (Java/Other ...
- HDU(3605),二分图多重匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others) ...
随机推荐
- OpenCV从入门到放弃(五):像素!
一.概念 1.图像本质上面是由数值组成的矩阵.矩阵中的一个元素相应一个像素. 2.对于灰度图像(黑白图像),像素是8位无符号数(CV_8U).0表示黑色,255表示白色.对于彩色图像,是用三原色数据合 ...
- Mariadb配置文件优化参数(仅供参考)
[client]#password= your_passwordport= 3306 socket= /tmp/mysql.sock!includedir /opt/local/mys ...
- 使用perl读取Excel
使用perl读取Excel 环境 windows 7 ActiveState Perl Win32::OLE[perl package] 基本功能 循环处理多个sheet 读取Excel单元,提取in ...
- http各种状态码具体解释
1XX (暂时响应) 100(继续) 请求者应当继续提出请求. 101(切换协议)请求者已要求server切换协议,server已确认并准备切换 2XX(成功) ·200(成功) ser ...
- 账号权限问题导致 masterha_check_repl 检查失败
在使用 masterha_check_repl --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1. ...
- Tokumx vs Mongodb
Mongodb是一个文档型nosql数据库 採用C++编写 Mongo DB最大的优势在于全部的数据持久操作都无需开发者手动编写SQL语句,直接调用方法就能够轻松的实现CRUD操作. 非常多人觉得mo ...
- Windows下启动ActiveMq端口被占用的解决办法
cd /D E:\RuntimeSoft\apache-activemq-5.11.0\binactivemq.bat start结果提示:端口号被占用. Windows下查看端口号被占用开始--运行 ...
- 【hdu 1527】取石子游戏
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...
- [HTML5] Focus management using CSS, HTML, and JavaScript
Something important to consider when coding a web application is managing the user's focus. For keyb ...
- Java泛型解析(02):通配符限定
Java泛型解析(02):通配符限定 考虑一个这种场景.计算数组中的最大元素. [code01] public class ArrayUtil { public static <T&g ...