您的位置:首页 > 其它

Saber's Board 北邮2016校赛

2017-03-30 14:32 274 查看
时间限制 5000 ms 内存限制 65536 KB

题目描述

In a parallel universe, Saber has won the champion of every kind of board games. She even defeated the AI program BetaGo recently! After all the victory she has got, Saber found life so boring that she decided to develop her own kind of board game. The new game named "Diamond Wars" involves two players to play on a randomly generated N∗M board, each grid is filled with red or blue, indicating the first and the second players. The players then decide an integer K by random. Next, each player take turns to fill a part of the board following the rules: one must choose a grid (x,y) in his color, K≤x≤N−K+1 and K≤y≤M−K+1, and if for all the grids (i,j)      that satisfy ∣i−x∣+∣j−y∣≤K−1                 , they are all of the player's color, he will color them to green and get 1 score. We call this (x,y) a valid grid. If one player chose an invalid (x,y), that grid as well as all grids (i,j)       satisfing the formula will become the opponent's color! The first one who is unable to move when there are still non-green grids on the board, or the one with less score at last will lose the game. As an expert in board games, Saber wants to know exactly how many valid grids the first player can choose at the very beginning. She is confident that she will win every game even being the second player to move.


输入格式

The input starts with an integer T (1≤T≤20),      indicating the number of test cases.
For each test case, the first line contains three integers N,M,K (1≤N,M≤100,1≤2∗K≤min(N+1,M+1)). The following N lines contain the board, each line with exactly M characters. We assume red be 'O' and blue be 'X' to simplify the problem.


输出格式

For each test case, print a line containing the answer to the problem Saber is interested in.


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
typedef struct {
int x, y;
}Point;
int main()
{
int t;
cin >> t;
char Map[105][1005];
while (t--)
{
int N, M, K;
cin >> N >> M >> K;
int i, j, k; Point temp;
cin.get();
vector<Point> a;
int total = 0;
for (i = 1; i <= N; i++)
{
for (j = 1; j <= M; j++)
{
cin >> Map[i][j];
if (Map[i][j] == 'X')
{
temp.x = i;
temp.y = j;
a.push_back(temp);
}
if (Map[i][j] == 'O'&&i >= K&&i <= N - K + 1 && j >= K&&j <= M - K + 1)
total++;
}
cin.get();
}
for (i = K; i <=N-K+1; i++)
{
for(j=K;j<=M-K+1;j++)
for(int k=0;k<a.size();k++)
if (Map[i][j] == 'O'&&abs((i - a[k].x)) + abs((j - a[k].y))<= (K-1))
{
total--;
break;
}
}
cout << total << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: