时间限制 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.

【本文出自http://blog.csdn.net/u012662688/article/details/51163528,转载请注明】

输入样例

1
4 5 2
XOOOO
OOOOX
OOOOO
OXXOO

输出样例

3

一个好好想一想,大家都能过的题,先枚举出所有符合条件的x、y,再枚举出所有符合条件的i、j即可。4重for循环。

#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 150
using namespace std;
int main(){int t,n,i,m,k;char str[N][N];for(scanf("%d",&t);t--;){scanf("%d%d%d",&n,&m,&k);for(i=1;i<=n;i++)scanf("%s",str[i]+1);int x,y;int ans=0;int sig;int px,py;for(x=k;x<=n-k+1;x++){for(y=k;y<=m-k+1;y++){sig=1;if(str[x][y]=='O'){for(px=1;px<=n&&sig;px++){for(py=1;py<=m&&sig;py++){if(abs(px-x)+abs(py-y)<=k-1){if(str[px][py]!='O')sig=0;}}}if(sig){ans++;}}}}printf("%d\n",ans);}return 0;
}

北邮OJ 1022. 16校赛-Saber's Board相关推荐

  1. 北邮OJ 981. 16校赛-Saber's Number Game

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Saber is fond of number games of various kinds, she particularly lik ...

  2. 北邮OJ 1027. 16校赛-Archer in Archery

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Archer(Emiya), also known as the red A, is famous for his talented s ...

  3. 北邮OJ 1021. 16校赛-Stone Game

    时间限制 4000 ms 内存限制 65536 KB 题目描述 Alice and Bob are old friends in game theory. This afternoon they me ...

  4. 北邮OJ 1010. 16校赛-Binary Strings

    时间限制 5000 ms 内存限制 65536 KB 题目描述 One day, the teacher asked Weishen to judge whether a binary string ...

  5. 北邮OJ 1005. 16校赛-Hawei Learning C

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Hawei is learning C programming language recently, but he is so naiv ...

  6. 北邮OJ 980. 16校赛-R_clover's Challenge

    时间限制 2000 ms 内存限制 65536 KB 题目描述 R_clover wants to challenge Mengmengda_wsw's math,so he give her a f ...

  7. 北邮OJ 884. 16校赛-Average Modulo

    时间限制 5000 ms 内存限制 65536 KB 题目描述 We define function g on an array as: g([a0,a1,⋯,an−1])=(Σn−1l=0al) m ...

  8. 北邮oj题库刷题计划(更新ing)

    北邮oj题库刷题计划(更新ing) 83. A + B Problem 84 Single Number 85. Three Points On A Line 120 日期 121 最值问题 122 ...

  9. 北邮OJ 141 虚数

    北邮OJ 虚数 #include <bits/stdc++.h> using namespace std; typedef struct fushu{int x; //实部 int y; ...

最新文章

  1. WaitForSingleObject和WaitForMultipleObjects用法
  2. FreeMarker标签介绍
  3. echarts仪表盘option_echarts仪表盘完整代码
  4. 编码utf-8的不可映射字符_MySQL 请不要使用“utf8”
  5. Spring Boot 集成 WebSocket通信信息推送!
  6. python 位置参数、默认参数、可变参数位置关系_python的位置参数、默认参数、关键字参数、可变参数区别...
  7. rpa文件怎么提取内容_怎么编辑pdf文件内容?有什么软件可以编辑pdf文件吗?
  8. 国科大prml10-无监督学习
  9. mysql为什么选innodb_为什么现在的MySQL都要使用innoDB引擎-Go语言中文社区
  10. java innodb存储引擎_MySQL InnoDB存储引擎的事务隔离级别
  11. 做一个完整的Java Web项目需要掌握的技能[转]
  12. win10关闭计算机休眠,小编教您win10怎么关闭休眠 win10关闭系统休眠方法
  13. ES3、ES4、ES5、ES6区别
  14. OneDrive 挂载为本地磁盘Ubuntu
  15. 算法工程师(机器学习)部分面试题(转载参考)
  16. 未明学院:保姆级四大par面面经和准备方法
  17. 2023 软件库APP下载系统源码 附卡密会员插件
  18. easyExcel的复杂表头多级表头导入
  19. 老男孩mysql运维dba实战21部完整版_老男孩Mysql DBA高级运维系列课程(16部)
  20. 技嘉z68主板驱动下载地址

热门文章

  1. 2021斯坦福图机器学习课程CS224W开课了,Jure Leskovec主讲
  2. 如何阅读AI顶会论文,搭建深度学习知识体系框架?
  3. 详解深度学习中的Normalization,不只是BN(2)
  4. c语言自增自减5运算符详解,巧用C语言中的自增自减运算符
  5. python 逗号作用 语句间_Python中逗号的三种作用
  6. curl怎么输出赋值_python怎么实现循环
  7. 深入浅出Java复用类【从字节码角度看toString调用机制、对象代理、组合与继承、转型、final、初始化】
  8. 【❤️算法系列之二叉树的实现(包含前序、中序、后序遍历以及节点的查找和删除)❤️】
  9. PL/SQL Developer中如何格式化SQL
  10. Java——将JSONP返回的结果转化为Java对象