Codevs 1022 覆盖
- 时间限制: 1 s
- 空间限制: 128000 KB
- 题目等级 : 大师 Master
题目描述 Description
有一个N×M的单位方格中,其中有些方格是水塘,其他方格是陆地。如果要用1×2的矩阵区覆盖(覆盖过程不容许有任何部分重叠)这个陆地,那么最多可以覆盖多少陆地面积。
输入描述 Input Description
输入文件的第一行是两个整数N,M (1<=N,M<=100),第二行为一个整数K(K<=50),接下来的K行,每行两个整数X,Y表示K个水塘的行列位置。(1<=X<=N,1<=Y<=M) 。
输出描述 Output Description
输出所覆盖的最大面积块(1×2面积算一块)。
样例输入 Sample Input
4 4
6
1 1
1 4
2 2
4 1
4 2
4 4
样例输出 Sample Output
4
题解:
对于每个空格,向它的上下左右连一条边,跑一遍匈牙利算法就好。
#include <iostream>
using namespace std;
int n, m, k, ans;
bool g[105][105], lian[10005], used[10005], line[10005][10005];
int hash(int x, int y)
{
return (x - 1) * m + y;
}
bool find(int x)
{
int xl, xh;
if(x % m)
{
xl = x % m;
xh = x / m + 1;
}
else
{
xl = m;
xh = x / m;
}
if(g[xh][xl])
return false;
for (int i = 1; i <= n * m; ++i)
if (line[x][i] && !used[i])
{
used[i] = true;
if(lian[i] == 0 || find(lian[i]))
{
lian[i] = x;
return true;
}
}
return false;
}
int main()
{
int h, l;
cin >> n >> m >> k;
for (int i = 0; i < k; ++i)
{
cin >> h >> l;
g[h][l] = true;
}
int ih, il;
for (int i = 1; i <= n * m; ++i)
{
if(i % m)
{
il = i % m;
ih = i / m + 1;
}
else
{
il = m;
ih = i / m;
}
if (!g[ih][il])
{
if (ih > 1)
if (!g[ih - 1][il])
line[i][i - m] = true;
if (il > 1)
if (!g[ih][il - 1])
line[i][i - 1] = true;
if (ih < n)
if (!g[ih + 1][il])
line[i][i + m] = true;
if (il < m)
if (!g[ih][il + 1])
line[i][i + 1] = true;
}
}
unsigned ans = 0;
for (int i = 1; i <= n * m; ++i)
{
for (int j = 1; j <= n * m; ++j)
used[j] = false;
if (find(i))
++ans;
}
cout << ans / 2;
}
Codevs 1022 覆盖的更多相关文章
- Code[VS] 1022 覆盖 题解
Code[VS] 1022 覆盖 题解 Hungary Algorithm 题目传送门:Code[VS] 1022 题目描述 Description 有一个N×M的单位方格中,其中有些方格是水塘,其 ...
- 【CODEVS】1022 覆盖
[算法]二分图匹配(最大流) [题解]对i+j进行奇偶染色,就可以保证相邻两格异色. 然后就是二分图了,对相邻格子连边跑最大流即可. #include<cstdio> #include&l ...
- 【wikioi】1022 覆盖(匈牙利)
http://www.wikioi.com/problem/1022/ 好不容易来一次1A,,水题啊.. 染色后裸匈牙利orz #include <cstdio> #include < ...
- CodeVS 线段覆盖1~5
#include <bits/stdc++.h> using namespace std; ; struct Info{int l,r;}P[Maxn]; int n,Cnt,F[Maxn ...
- codevs 版刷计划(1000-1099)
Diamond咋都是模板题... 开个坑刷codevs的Master题.巩固一下姿势. 目前AC的题目:1001,1021,1022, 1001.舒适的路线(并查集) 求出无向图s到t路径上的min( ...
- 【BZOJ-3589】动态树 树链剖分 + 线段树 + 线段覆盖(特殊的技巧)
3589: 动态树 Time Limit: 30 Sec Memory Limit: 1024 MBSubmit: 405 Solved: 137[Submit][Status][Discuss] ...
- 匈牙利算法实战codevs1022覆盖
1022 覆盖 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 查看运行结果 题目描述 Description 有一个N×M的单位方格中 ...
- 【经典】Noip贪心
一.经典例题 例一:排队接水 题意:n个人到r个水龙头接水,装满水桶的时间分别是t1,t2,t3.... 接水时间是整数且互不相等,怎样安排顺序使每个人等待的 时间和最小. 题解:排队越靠前计算次数越 ...
- codevs——T1214 线段覆盖
http://codevs.cn/problem/1214/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descr ...
随机推荐
- http://blog.csdn.net/lipeng32768/article/details/50845547
http://blog.csdn.net/lipeng32768/article/details/50845547
- OAuth2授权页面state参数的设计
场景描述: 第三方应用:freeshare 账号系统:account freeshare点击登录,跳转到account页面进行授权. 具体例子可以参考我们的freeshare系统:http://fre ...
- adams/car 怎么进入template builder模块
打开C:\Documents and Settings\Administrator文件夹下的acar.cfg文件,将 Desired user mode (standard/expert)ENVIRO ...
- ural 1339. Babies
1339. Babies Time limit: 1.0 secondMemory limit: 64 MB O tempora! O mores! Present-day babies progre ...
- python 代码片段21
#coding=utf-8 @doco def foo(): pass ''' deco把foo函数拿过来,加上一些额外的功能再重新赋值给foo,如下 ''' foo=deco(foo) def lo ...
- [转]linux(centos)搭建SVN服务器
转自:http://blog.163.com/longsu2010@yeah/blog/static/173612348201202114212933/ 安装步骤如下: 1.yum install ...
- Spring AOP报错处理 Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误
[转] 解决方法: http://forum.springsource.org/showthread.php?85016-IllegalArgumentException-with-Applicati ...
- 桌面每日一句--桌面翻译工具(有道翻译,微软翻译,Google翻译)
现在的翻译软件功能越来越多,也越来越臃肿,还不时弹广告,真的很烦恼. 鉴于这种情况,自己做了个翻译软件,能满足日常需求就好了.需要用的时候可以直接在桌面输入单词翻译,或者直接使用快捷键呼出翻译窗口.最 ...
- ACM 字符串替换
字符串替换 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 编写一个程序实现将字符串中的所有"you"替换成"we" 输入 ...
- ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Weird Cryptography Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...