vijos p1729 Knights
描述
在一个N*N的正方形棋盘上,放置了一些骑士。我们将棋盘的行用1开始的N个自然数标记,将列用'A'开始的N个大写英文字母标记。举个例子来说,一个标准的8*8的国际象棋棋盘的行标记为1..8,列标记为A..H,D3、H1分别表示棋盘上第3行第4列和第1行第8列的格子。
骑士是这样一类棋子。若一个骑士放置在格子(x, y)。那么格子(x-2, y-1), (x-2, y+1), (x-1, y-2), (x-1, y+2), (x+1, y-2), (x+1, y+2), (x+2, y-1), (x+2, y+1)如果在棋盘内的话,就都处于这个骑士的攻击范围内。
如果若干个骑士在棋盘上的一种放置方法能使得没有一个骑士处在其它骑士的攻击范围内,那么称为和谐的方案。现在给定一个棋盘,上面已经放置了M个骑士。你的任务是拿走尽可能少的骑士,使得剩余的骑士构成一个和谐的方案。
格式
输入格式
第一行,两个正整数N,M,分别表示棋盘的大小,和骑士的数目。
以下M行,每行一个字符串,描述一个骑士的坐标。
输出格式
输出一行,一个整数,表示至少拿走多少个骑士。
限制
每个测试点1s
提示
30%的数据满足,1 <= N <= 4.
100%的数据满足,1 <= N <= 26,骑士的坐标格式均合法,任意两个骑士的位置都不同。
来源
Topcoder
/*
Problem:
OJ:
User:S.B.S.
Time:
Memory:
Length:
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#include<functional>
#include<bitset>
#include<vector>
#include<list>
#include<map>
#define maxn 100001
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x3f3f3f3f
#define maxm 1001
#define mod 998244353
//#define LOCAL
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int dx[]={-,-,-,-,,,,};
const int dy[]={-,-,,,,,-,-};
int n,m;
struct EDGE
{
int from;
int to;
int next;
}e[maxn];
struct NODE
{
int x;
int y;
}a[maxn];
int head[maxn];
int tot;
int vis[maxm][maxm],ins[maxn];
int py[maxn];
int ans;
inline void addedge(int u,int v)
{
tot++;
e[tot].from=u;
e[tot].to=v;
e[tot].next=head[u];
head[u]=tot;
}
inline bool path(int x)
{
int y;
for(int i=head[x];i;i=e[i].next)
{
if(!ins[y=e[i].to]){
ins[y]=;
if(!py[y]||path(py[y])){
py[y]=x;
return true;
}
}
}
return false;
}
int main()
{
// std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
cin>>n>>m;
char s[];
F(i,,m){
gets(s+);
a[i].x=s[]-'A'+;
int len=strlen(s+);
F(j,,len){
a[i].y*=;
a[i].y+=s[j]-'';
}
vis[a[i].x][a[i].y]=i;
}
F(i,,m){
F(k,,){
int fx=dx[k]+a[i].x,fy=dy[k]+a[i].y;
if(fx<||fy<||fx>n||fy>n||!vis[fx][fy]) continue;
addedge(i,vis[fx][fy]);
}
}
F(i,,m){
if((a[i].x+a[i].y)&){
M(ins,);
if(path(i)) ans++;
}
}
cout<<ans<<endl;
return ;
}
vijos p1729 Knights的更多相关文章
- 【vijos】1729 Knights(匈牙利)
https://vijos.org/p/1729 这题好奇葩,为嘛N开到30就会re啊..........n<=26吗.... sad 因为根据棋子的分布,能攻击的一定各在一黑白格上,所以直接二 ...
- 【BZOJ 1061】【Vijos 1825】【NOI 2008】志愿者招募
http://www.lydsy.com/JudgeOnline/problem.php?id=1061 https://vijos.org/p/1825 直接上姜爷论文... #include< ...
- POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 12439 Acce ...
- vijos P1915 解方程 加强版
背景 B酱为NOIP 2014出了一道有趣的题目, 可是在NOIP现场, B酱发现数据规模给错了, 他很伤心, 哭得很可怜..... 为了安慰可怜的B酱, vijos刻意挂出来了真实的题目! 描述 已 ...
- vijos P1780 【NOIP2012】 开车旅行
描述 小\(A\)和小\(B\)决定利用假期外出旅行,他们将想去的城市从\(1\)到\(N\)编号,且编号较小的城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市\(i\)的海拔高度为 ...
- 【BZOJ 2541】【Vijos 1366】【CTSC 2000】冰原探险
http://www.lydsy.com/JudgeOnline/problem.php?id=2541 https://vijos.org/p/1366 loli秘制大爆搜_(:з」∠)_坑了好久啊 ...
- 【BZOJ 1065】【Vijos 1826】【NOI 2008】奥运物流
http://www.lydsy.com/JudgeOnline/problem.php?id=1065 https://vijos.org/p/1826 好难的题啊TWT ∈我这辈子也想不出来系列~ ...
- 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 ...
随机推荐
- 【LOJ】#2024. 「JLOI / SHOI2016」侦查守卫
题解 童年的回忆! 想当初,这是我考的第一次省选,我当时初二,我什么都不会,然后看着这个东西,是不是能用我一个月前才会的求lca,光这个lca我就调了一个多小时= =,然后整场五个小时,我觉得其他题不 ...
- 本机ip和127.0.0.1的区别
简介 连接上因特网的每一台计算机都会有一个IP地址, 在linux下可以使用命令ifconfig来查看本机的ip地址(windows为ipconfig), 比如我当前电脑的ip地址为192.168.0 ...
- Tomcat --> Cannot create a server using the selected type
今天在eclipse想把之前的Tomcat 6删掉,重新配置一个,不料没有下一步 Cannot create a server using the selected type 这句话出现在窗口上面,应 ...
- Wannafly挑战赛9 C - 列一列
链接:https://www.nowcoder.com/acm/contest/71/C来源:牛客网 题目描述 小W在计算一个数列{An},其中A1=1,A2=2,An+2=An+1+An.尽管他计算 ...
- NCPC 2016 October 8,2016 Artwork
Problem A Artwork Problem ID: artwork Time limit: 4 seconds A template for an artwork is a white gri ...
- Little Elephant and Array 线段树
题目:http://codeforces.com/problemset/problem/220/B 题意 给定一组数据,多次询问区间内某数字出现次数与该数字数值相同的数的个数 思路 一看到区间查询,就 ...
- SSH项目整合基本步骤
SSH项目整合基本步骤 一.项目简介 该项目是由Spring4.Struts2 以及 Hibernate4 整合搭建的 web 项目,把Action分开编写,便于查看,使用JSTL.EL标签. 二.项 ...
- [POI2015]Wilcze doły
[POI2015]Wilcze doły 题目大意: 给定一个长度为\(n(n\le2\times10^6)\)的数列\(A(1\le A_i\le10^9)\),可以从中选取不超过\(d\)个连续数 ...
- 鸟哥的私房菜:Bash shell(四)-Bash shell的使用环境
Bash shell(四)-Bash shell的使用环境 是否记得我们登入主机的时候,屏幕上头会有一些说明文字,告知我们的 Linux 版本啊什么的, 还有,登入的时候,我们还可以给予使用者一些 ...
- BZOJ 2142 礼物 组合数学 CRT 中国剩余定理
2142: 礼物 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1450 Solved: 593[Submit][Status][Discuss] ...