Problem D: Queens, Knights and Pawns
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88443#problem/D

Description

You all are familiar with the famous 8-queens problem which asks you to place 8 queens on a chess board so no two attack each other. In this problem, you will be given locations of queens and knights and pawns and asked to find how many of the unoccupied squares on the board are not under attack from either a queen or a knight (or both). We’ll call such squares “safe” squares. Here, pawns will only serve as blockers and have no capturing ability. The board below has 6 safe squares. (The shaded squares are safe.) Q P Q K Recall that a knight moves to any unoccupied square that is on the opposite corner of a 2x3 rectangle from its current position; a queen moves to any square that is visible in any of the eight horizontal, vertical, and diagonal directions from the current position. Note that the movement of a queen can be blocked by another piece, while a knight’s movement can not.

Input

There will be multiple test cases. Each test case will consist of 4 lines. The first line will contain two integers n and m, indicating the dimensions of the board, giving rows and columns, respectively. Neither integer will exceed 1000. The next three lines will each be of the form k r1 c1 r2 c2 · · · rk ck indicating the location of the queens, knights and pawns, respectively. The numbering of the rows and columns will start at one. There will be no more than 100 of any one piece. Values of n = m = 0 indicate end of input.

Output

Each test case should generate one line of the form Board b has s safe squares. where b is the number of the board (starting at one) and you supply the correct value for s.

Sample Input

4 4 2 1 4 2 4 1 1 2 1 2 3 2 3 1 1 2 1 1 1 0 1000 1000 1 3 3 00 0 0

Sample Output

Board 1 has 6 safe squares. Board 2 has 0 safe squares. Board 3 has 996998 safe squares.

HINT

题意

给你一个棋盘,棋盘上面有士兵,有皇后,有马

士兵不会动,皇后攻击范围是八个方向的直线,马是日字

然后问你最后有多少个格子是安全的

题解

直接暴力就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int n,m;
int s[][];
//queens, knights and pawns
int ans=;
void check(int x,int y)
{
if(x<||x>n||y<||y>m)
return;
if(s[x][y]==)
{
s[x][y]=;
ans++;
}
}
void at_queue(int x,int y)
{
check(x,y);
for(int i=x;i<=n;i++)
{
if(s[i][y]==)
break;
check(i,y);
}
for(int i=x;i>=;i--)
{
if(s[i][y]==)
break;
check(i,y);
}
for(int i=y;i>=;i--)
{
if(s[x][i]==)
break;
check(x,i);
}
for(int i=y;i<=m;i++)
{
if(s[x][i]==)
break;
check(x,i);
}
for(int i=x,j=y;i<=n&&j<=m;i++,j++)
{
if(s[i][j]==)
break;
check(i,j);
}
for(int i=x,j=y;i>=&&j>=;j--,i--)
{
if(s[i][j]==)
break;
check(i,j);
}
for(int i=x,j=y;i>=&&j<=m;i--,j++)
{
if(s[i][j]==)
break;
check(i,j);
}
for(int i=x,j=y;i<=n&&j>=;i++,j--)
{
if(s[i][j]==)
break;
check(i,j);
}
}
void at_knight(int x,int y)
{
check(x,y);
check(x+,y+);
check(x+,y+);
check(x-,y+);
check(x-,y+);
check(x+,y-);
check(x+,y-);
check(x-,y-);
check(x-,y-);
}
struct node
{
int x,y;
};
node que[];
node kni[];
int main()
{
int t=;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)
break;
ans=;
memset(que,,sizeof(que));
memset(kni,,sizeof(kni));
memset(s,,sizeof(s));
int k1=read();
for(int i=;i<k1;i++)
{
que[i].x=read();
que[i].y=read();
}
int k2=read();
for(int i=;i<k2;i++)
{
kni[i].x=read();
kni[i].y=read();
int x=kni[i].x,y=kni[i].y;
if(s[x][y]==)
{
s[x][y]=;
ans++;
}
}
int k3=read();
for(int i=;i<k3;i++)
{
int x=read();
int y=read();
if(s[x][y]==)
{
s[x][y]=;
ans++;
}
}
for(int i=;i<k1;i++)
at_queue(que[i].x,que[i].y);
for(int i=;i<k2;i++)
at_knight(kni[i].x,kni[i].y);
printf("Board %d has %d safe squares.\n",t++,n*m-ans);
}
}

Codeforces Gym 100650D Queens, Knights and Pawns 暴力的更多相关文章

  1. sicily 1172. Queens, Knights and Pawns

    Description You all are familiar with the famous 8-queens problem which asks you to place 8 queens o ...

  2. Codeforces Gym 100803F There is No Alternative 暴力Kruskal

    There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...

  3. Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力

    原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...

  4. Codeforces Gym 100342C Problem C. Painting Cottages 暴力

    Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...

  5. Codeforces Gym 100513I I. Sale in GameStore 暴力

    I. Sale in GameStore Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/p ...

  6. Codeforces Gym 100203G G - Good elements 标记暴力

    G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  7. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  8. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  9. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

随机推荐

  1. chrome console js多行输入

    一直以来,Chrome控制台都缺少象IE调试台那样的多行执行模式.  今天意外发现Chrome其实也支持多行模式.默认在Chrome控制台上输入回车后会执行该命令,只需要通过输入Shift+Enter ...

  2. View.VISIBLE、INVISIBLE、GONE的区别

    android中UI应用的开发中经常会使用view.setVisibility()来设置控件的可见性,其中该函数有3个可选值,他们有着不同的含义: View.VISIBLE--->可见View. ...

  3. android中sqlite3常用命令

    1)打开数据库 在adb shell模式下执行命令sqlite3 + 数据库名称,例如打开email中的EmailProvider.db数据库: 2)sqlite3特殊命令 大多数候,sqlite3读 ...

  4. ECshop 二次开发模板教程2

    不知道大家是学会用循环了呢,还是我的言语实在有问题,大家实在无法完成阅读哦,居然大家都没有问题,暂时心里安慰,把他当做好事情,大家都会调用了,呵呵,那我们继续循环调用商品了!好,继续在我们昨天的基础上 ...

  5. codeforces 675C Money Transfers map

    上面是官方题解,写的很好,然后就A了,就是找到前缀和相等的最多区间,这样就可以减去更多的1 然后肯定很多人肯定很奇怪为什么从1开始数,其实从2开始也一样,因为是个环,从哪里开始记录前缀和都一样 我们的 ...

  6. <转>详解DNS的常用记录(下):DNS系列之三

    在上篇博文中我们介绍了DNS服务器中几种不可或缺的记录,包括A记录,NS记录和SOA记录.本篇博文中我们将继续为大家介绍DNS的另外几种常用记录,希望能对大家了解DNS有所帮助. 四 MX记录 MX记 ...

  7. 关于CCSprite改变box2d刚体位置以及角度。

    同事今天在讨论一个事情,box2d中,body不可以直接设置位置,这样是不合理的,因为在物理的世界,你去左右它的物理检测.它就没有存在的必要了.但是,有人就想直接用box2d的碰撞.不用物理模拟.怎么 ...

  8. data audit on hadoop fs

    最近项目中遇到了存储在HDFS上的数据格式不对,是由于数据中带有\r\n的字符,程序处理的时候没有考虑到这些情况.历史数据大概有一年的时间,需要把错误的数据或者重复的数据给删除了,保留正确的数据,项目 ...

  9. Multiple reportviewers on one page With reportviwer 11.0

    Hi,  evreryone: When I use  VS 2012  to create report with reportviwer 11.0, I  meet a  problem abou ...

  10. 【Hadoop学习】HDFS中的集中化缓存管理

    Hadoop版本:2.6.0 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4146398.html 概述 ...