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的更多相关文章

  1. POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Acce ...

  2. POJ 2942 Knights of the Round Table

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10911   Acce ...

  3. LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...

  4. 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS

    [Usaco2005 Dec]Knights of Ni 骑士 Description  贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...

  5. Knights of the Round Table-POJ2942(双连通分量+交叉染色)

    Knights of the Round Table Description Being a knight is a very attractive career: searching for the ...

  6. poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 9169   Accep ...

  7. LightOJ 1315 - Game of Hyper Knights(博弈sg函数)

    G - Game of Hyper Knights Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...

  8. [BZOJ 4436][Cerc2015]Kernel Knights

    [Cerc2015]Kernel Knights Time Limit: 2 Sec Memory Limit: 512 MBSubmit: 5 Solved: 4[Submit][Status][D ...

  9. UVALive 7334 Kernel Knights (dfs)

    Kernel Knights 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/K Description Jousting is ...

随机推荐

  1. Robocopy进行大量迁移

    建议使用 Windows Server 2012 R2 或 Windows Server 2012 随附的 Robocopy.exe 版本. 即然官方建议我们用2012或2012R2所带的Roboco ...

  2. 《从0到1》读书笔记第一章&quot;未来的挑战&quot;第1记:把握潮流风向

    这几天刚到手当前炙手可热的来自PayPal创始人Peter Thiel的<Zero to One>.中文名<从0到1>,由高玉芳翻译.中信出版社出版.由于到货时刚好有事情在忙, ...

  3. GLib-GObject-WARNING **: Two different plugins tried to register

    使用 Ubuntu vivid 的 glib-2.44.1 的程序总是打印类似这种警告: GLib-GObject-WARNING **: Two different plugins tried to ...

  4. ascii与unicode,utf-8小结

    ascii是以一个字节存储英文和特殊字符,不支持中文的处理.unicode占用的是两个字节,可以存储中文.utf-8占用三个字节,可以根据存储的内容进行中英文的转换. Python的解释器是不支持中文 ...

  5. 链接脚本在编程中的高级运用之二——执行时库和C++特性支持

    我们在链接脚本在编程中的高级运用之中的一个可变长数组中已经讲述了编译链接的原理,并且以uboot命令为例具体介绍链接脚本怎样实现可变长数组. 本章在前者的基础上继续讲述链接脚本在执行时库中的高级应用技 ...

  6. C/C++ scanf 函数中%s 和%c 的简单差别

    首先声明:在键盘中敲入字符后,字符会首先保存在键盘缓冲区中供scanf函数读取(scanf.getchar等函数是读取缓冲区,getch函数是读取的控制台信息,即为直接从键盘读取).另外特别注意键盘上 ...

  7. 行转列--Excel和数据库的完美结合

    入职到如今已经有一段时间了,除了不断完好新功能外,线上运维也是一项非常重要的任务,每天都须要占用一 定量的时间来处理,这时候如何高效准确的来解决这些问题是非常值得考虑的.       今天客服人员给我 ...

  8. 记录下docker的常用命令

    常用命令: docker images:查看本地所有镜像 docker pull  centos:7:从仓库中获取镜像 docker ps:列出所有正在运行的容器 docker ps -a:列出所有容 ...

  9. 搭建nodejs服务,访问本地站点文件

    搭建nodejs服务器步骤: 1.安装nodejs服务(从官网下载安装) 2.在自己定义的目录下新建服务器文件如 server.js 例如,我在E:\PhpProject\html5\websocke ...

  10. ABAP 读取服务器CSV文件到内表

    DATA: BEGIN OF gs_data , cola TYPE string, colb TYPE string, ... END OF gs_data, gt_data LIKE TABLE ...