北邮OJ 1022. 16校赛-Saber's Board

15 篇文章 0 订阅
9 篇文章 0 订阅

题目描述

    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  NM  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,  KxNK+1  and  KyMK+1 , and if for all the grids  (i,j)       that satisfy  ix+jyK1                  , 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 (1T20) ,      indicating the number of test cases. 
    For each test case, the first line contains three integers  N,M,K (1N,M100,12Kmin(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;
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值