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; }
相关文章推荐
- 2016旷视杯清华校赛总结(部分题目解法)
- gdut 2016校赛决赛 Problem F 我是好人4
- 二分_Mode(2016swust校赛)
- 2016多校赛 Teacher Bo(曼哈顿距离)
- 2016 哈理工校赛H
- 广东工业大学2016校赛决赛-网络赛 1169 Problem A: Krito的讨伐 优先队列
- 北邮OJ 1022. 16校赛-Saber's Board
- 2016西电校赛网络赛 Problem A z1+z2
- 暴力____Football(2016swust校赛)
- 北邮校赛 F. Gabriel's Pocket Money(树状数组)
- 北邮OJ 884. 16校赛-Average Modulo
- 2016西电校赛网络赛 Problem C 寻找万神
- G:Prefixes and Suffixes(2016华工安信证券杯校赛)(还没搞懂!!)
- [2016校赛]两个简单的小题
- 北邮校赛 H. Black-white Tree (猜的)
- HDU 5762 Teacher Bo 2016多校赛第三场 鸽巢原理
- 北邮OJ 980. 16校赛-R_clover's Challenge
- 北邮OJ 2016网预 - Saber's Conjecture
- 2016西电校赛网络赛 Problem D 抢人头
- 2016移动开发校赛之Android实践