[BZOJ1381]Knights
Description
在一个N*N的棋盘上,有些小方格不能放骑士,棋盘上有若干骑士,任一个骑士不在其它骑士的攻击范围内,请输出最多可以放多少个骑士. 骑士攻击的点如中国象棋中的马,可以攻击8个点.
Input
第一行给出N,M代表棋盘的大小及故障点的个数 下面M行,给出故障点的坐标
1<=n<=200, 0<=m
Output
最多可以放多少个
Sample Input
3 2
1 1
3 3
Sample Output
5
二分图最大独立点集,由于\(N\)不是特别大,因此我们可以暴力枚举连边。
值得注意的一点是,我们需要提前规定好是由白块匹配黑块还是由黑块匹配白块,否则匹配就失去了它的准确性
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=2e2;
const int dx[8]={-2,-2,-1,-1,1,1,2,2};
const int dy[8]={1,-1,2,-2,2,-2,1,-1};
int pre[N*N*4+10],now[N*N/2+10],child[N*N*4+10],path[N*N/2+10],col[2];
int num[N+10][N+10];
bool use[N*N/2+10],map[N+10][N+10];
int n,m,ans,tot;
void join(int x,int y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}
bool in_map(int x,int y){return x>0&&x<=n&&y>0&&y<=n&&!map[x][y];}
void connect(int x,int y){
for (int i=0;i<8;i++){
int tx=x+dx[i],ty=y+dy[i];
if (in_map(tx,ty)) join(num[x][y],num[tx][ty]);
}
}
bool check(int x){
for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){
if (use[son]) continue;
use[son]=1;
if (path[son]<0||check(path[son])){
path[son]=x;
return 1;
}
}
return 0;
}
int main(){
n=read(),m=read();
memset(path,-1,sizeof(path));
for (int i=1;i<=m;i++) map[read()][read()]=1;
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (!map[i][j]) num[i][j]=++col[(i+j)&1];
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (!map[i][j]&&(i+j)&1) connect(i,j);
for (int i=1;i<=col[1];i++){
memset(use,0,sizeof(use));
if (check(i)) ans++;
}
printf("%d\n",col[0]+col[1]-ans);
return 0;
}
[BZOJ1381]Knights的更多相关文章
- POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 12439 Acce ...
- POJ 2942 Knights of the Round Table
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 10911 Acce ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS
[Usaco2005 Dec]Knights of Ni 骑士 Description 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...
- Knights of the Round Table-POJ2942(双连通分量+交叉染色)
Knights of the Round Table Description Being a knight is a very attractive career: searching for the ...
- poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 9169 Accep ...
- LightOJ 1315 - Game of Hyper Knights(博弈sg函数)
G - Game of Hyper Knights Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & ...
- [BZOJ 4436][Cerc2015]Kernel Knights
[Cerc2015]Kernel Knights Time Limit: 2 Sec Memory Limit: 512 MBSubmit: 5 Solved: 4[Submit][Status][D ...
- UVALive 7334 Kernel Knights (dfs)
Kernel Knights 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/K Description Jousting is ...
随机推荐
- Spring事务管理概述
以下内容引用自http://wiki.jikexueyuan.com/project/spring/transaction-management.html: 数据库事务是一个被视为单一的工作单元的操作 ...
- ArcEngine影像图配准
转自原文ArcEngine影像图配准 影像图配准主要包括以下几个方面 1.打开影像图 2.配准 3.影像图入库/保存 1.打开影像图的代码以前已经写过了. 2.配准 配准 主要使用IGeoRefe ...
- 【python】对象和面向对象
类的定义 python支持多重继承,在类名后面的小括号中,可以列出多个类名,以逗号分割. __init__方法在类的实例创建后被立即调用,注意与c++中构造函数不一样,因为对象在调用__init__时 ...
- Linux下进程信息的深入分析
这里我们主要介绍进程的状态,进程的状态可以通过/proc/PID/status来查看,也可以通过/proc/PID/stat来查看. 如果说到工具大家用的最多的ps也可以看到进程的信息.这里我们通过/ ...
- performSelector调用和直接调用的区别
今天在准备出笔试题的过程中随便搜了一下其他的笔试题,看到其中一个就是关于performSelector与直接调用的区别. 个人感觉这其实是一个陷阱题,因为大部分应用场景下,用哪一种都可以,可以说是没有 ...
- How to: Use Submix Voices
How to: Use Submix Voices:https://msdn.microsoft.com/en-us/library/windows/desktop/ee415794(v=vs.85) ...
- getifaddrs
getifaddrs 获取本地网络接口的信息.在路由器上可以用这个接口来获取wan/lan等接口当前的ip地址,广播地址等信息. #include <sys/types.h> #inclu ...
- 【iOS系列】-UITableViewCell的展开与收缩的实现思路
UITableViewCell的展开与收缩的实现思路 现在项目中很多地方都会用到,所以我这里介绍一种可以复用的思路,这与文章后面的Swift的实现思路不同,具体大家可自行对比. Demo项目地址 开始 ...
- 查询局域网内全部电脑IP和mac地址等信息
怎么查询局域网内全部电脑IP和mac地址等信息_百度经验 https://jingyan.baidu.com/article/54b6b9c0348e432d583b47c1.html 枚举ping ...
- SAP 常用增强记录文档
转自:http://blog.csdn.net/budaha 20170215需要一个PR 修改保存时候的增强,目的是同步PR的处理状态 EBAN-STATU 到一个自建表ZTPRTOPO,记得有个P ...