POJ 2446 最小点覆盖
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 14787 | Accepted: 4607 |
Description

We call a grid, which doesn’t contain a hole, a normal grid. Bob has to follow the rules below:
1. Any normal grid should be covered with exactly one card.
2. One card should cover exactly 2 normal adjacent grids.
Some examples are given in the figures below:
A VALID solution.
An invalid solution, because the hole of red color is covered with a card.
An invalid solution, because there exists a grid, which is not covered.
Your task is to help Bob to decide whether or not the chessboard can be covered according to the rules above.
Input
Output
Sample Input
4 3 2
2 1
3 3
Sample Output
YES
Hint

A possible solution for the sample input.
Source
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 35 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} int n, m;
vector<int>ve[N*N];
int from[N*N];
bool visited[N*N]; int march(int u){
int i, v;
for(i=;i<ve[u].size();i++){
v=ve[u][i];
if(!visited[v]){
visited[v]=true;
if(from[v]==-||march(from[v])){
from[v]=u;
return ;
}
}
}
return ;
}
int map[N][N];
main()
{
int i, j, k; int x, y;
while(scanf("%d %d %d",&n,&m,&k)==){
memset(map,-,sizeof(map));
int maxh=;
for(i=;i<n;i++){
for(j=;j<m;j++){
if(j==){
if(i==) map[i][j]=;
else {
if(m&) map[i][j]=map[i-][m-]+;
else map[i][j]=map[i-][m-]+;
}
}
else map[i][j]=map[i][j-]+;
maxh=max(maxh,map[i][j]);
// printf("%d ",map[i][j]);
}
//cout<<endl;
}
for(i=;i<k;i++){
scanf("%d %d",&x,&y);
map[y-][x-]=-;
}
int nn=;
for(i=;i<n;i++){
for(j=;j<m;j++){
if(map[i][j]==-) nn++;
}
} for(i=;i<=maxh;i++) ve[i].clear();
for(i=;i<n;i++){
for(j=;j<m;j++){
if(map[i][j]!=-&&(map[i][j]&)){
if(i>&&map[i-][j]!=-) ve[map[i][j]].push_back(map[i-][j]);
if(i<n-&&map[i+][j]!=-) ve[map[i][j]].push_back(map[i+][j]);
if(j>&&map[i][j-]!=-) ve[map[i][j]].push_back(map[i][j-]);
if(j<m-&&map[i][j+]!=-) ve[map[i][j]].push_back(map[i][j+]);
}
}
}
int num=;
memset(from,-,sizeof(from));
for(i=;i<=maxh;i++){
memset(visited,false,sizeof(visited));
if((i&)&&march(i)) num++;
}
if(num*==n*m-nn) printf("YES\n");
else printf("NO\n");
}
}
POJ 2446 最小点覆盖的更多相关文章
- POJ 2226 最小点覆盖(经典建图)
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8881 Accepted: 3300 Desc ...
- poj 3041 最小点覆盖=最大匹配
#include<stdio.h> #include<string.h> #define N 510 int map[N][N],n,mark[N],link[N]; in ...
- Poj(1325),最小点覆盖
题目链接:http://poj.org/problem?id=1325 Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total ...
- poj 1325 Machine Schedule 最小点覆盖
题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...
- POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)
题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
- poj 3041 Asteroids(最小点覆盖)
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3041 Asteroids (二分图最小点覆盖)
题目链接:http://poj.org/problem?id=3041 在一个n*n的地图中,有m和障碍物,你每一次可以消除一行或者一列的障碍物,问你最少消除几次可以将障碍物全部清除. 用二分图将行( ...
- [POJ] 2226 Muddy Fields(二分图最小点覆盖)
题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ...
- 二分图 最小点覆盖 poj 3041
题目链接:Asteroids - POJ 3041 - Virtual Judge https://vjudge.net/problem/POJ-3041 第一行输入一个n和一个m表示在n*n的网格 ...
随机推荐
- Windows下pry安装和配置
Windows下pry安装和配置 pry是一个增强型的交互式命令行工具,比irb强大. 有自动完成功能,自动缩进,有颜色.有更强大的调试功能. pry 安装很简单. 在终端输入: gem instal ...
- AppleWatch___学习笔记(二)UI布局和UI控件
1.UI布局 直接开发,你会发现Apple Watch并不支持AutoLayout,WatchKit里有个类叫做WKInterfaceGroup,乍一看像是UIView,但是这货其实是用来布局的.从 ...
- Xamarin
快速建立原生(Native)的行动装置应用程序: 程序代码共享: 与 Visual Studio 整合: 确保第一时间更新: 原生的应用程序效能:
- 解决连接VPN后无法上网问题
解决连接VPN后无法上网问题 VPN的英文全称是“Virtual Private Network”,翻译过来就是“虚拟专用网络”.顾名思义,虚拟专用网络可以把它理解成是虚拟出来的企业内部专线. 在公司 ...
- phpcms V9 数据模型基类
在学习<phpcms V9首页模板文件解析>的第七步,我们看到content_model类,文件路径:phpcms/model/content_model.class.php 从代码中,可 ...
- 配置DNS服务器
一.配置基本的DNS 服务器(包含正向解析和反向解析)域名:abc.com服务器IP:10.1.2.11 1. 编辑主配置文件/etc/named.conf---------------------- ...
- CSS3 笔记一(Rounded Corners/Border Images/Backgrounds)
CSS3 Rounded Corners The border-radius property is a shorthand property for setting the four border- ...
- Java多线程之Lock的使用
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...
- EF中使用linq进行关联查询
EF使用linq进行多表查询是完全可以的,最后ToList()调用的时候回产生一条分页的sql语句,所以并不是全部查询再分页的.所以不会影响查询的性能 public void TestLinq() { ...
- 2016年12月24日 星期六 --出埃及记 Exodus 21:19
2016年12月24日 星期六 --出埃及记 Exodus 21:19 the one who struck the blow will not be held responsible if the ...