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的网格 ...
随机推荐
- cmd运行sql server安装
cmd运行sql server安装 SQL2012非群集安装_更新到最新版本.bat setup.exe /UpdateSource=.\hotfix\Latest /ACTION="Ins ...
- Java多线程编程——进阶篇二
一.线程的交互 a.线程交互的基础知识 线程交互知识点需要从java.lang.Object的类的三个方法来学习: void notify() 唤醒在此对象监视器上等待的单个 ...
- Java类的基本运行顺序
不看不知道,一看还真吓了一跳!Java类的基本运行顺序你真的知道吗?如果你有疑惑,那就看下面这篇文章吧. 原文出自:[url]http://column.ibeifeng.com/chenchen ...
- Spark实战4:异常检测算法Scala语言
异常检测原理是根据训练数据的高斯分布,计算均值和方差,若测试数据样本点带入高斯公式计算的概率低于某个阈值(0.1),判定为异常点. 1 创建数据集转化工具类,把csv数据集转化为RDD数据结构 imp ...
- Java菜鸟学习 Script 脚本语言(简介)
script 可以写在head里 也可以写在body里 还可以写在 /html后面 script 也是成对出现的 <script></script> 他有三种常见的对话框 1 ...
- EF获取一个或者多个字段
有时候直接查询出一个实体,比较浪费性能,对于字段比较少的表来说差异不大,但是如果一个表有几十个字段,你只要取出一个字段或者几个字段,而取出整个实体,性能就会有差异了. /// <summary& ...
- js产生随机数并加入数组
<!doctype html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- 【leetcode❤python】 190. Reverse Bits
#-*- coding: UTF-8 -*- class Solution: # @param n, an integer # @return an integer def reve ...
- Dialog , ProgressDialog , PopWindow 区别
本质区别: Dialog:非阻塞对话框,弹出对话框时时,后台还可以做事情,点击背景时,对话框消失 ProgressDialog:带有圆形进度或者条形进度的对话框,一般结合handler使用.任务完成后 ...
- Json不知道key值情况下获取第一个键值对
JObject jsonData = new JObject(); jsonData.Add("1", "1"); jsonData.Add("2&q ...