hdu2699 Five in a Row 暴力穷举

PAT (Advanced Level) L1-6. 连续因子 for循环暴力 L1-6. 连续因子 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一个正整数N的因子中可能存在若干连续的数字。例如630可以分解为3*5*6*7,其中5、6、7就是3个连续的数字。给定任一正整数N, 阅读详情

Five in a Row

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 310    Accepted Submission(s): 134


Problem Description
The ACM Team of WHU is planning an online AI arena for Go-bang (Five in a Row). Now, we need some help.

We all know the famous game "Five in a Row". It is traditionally played with go pieces (black and white stones) on a go
board (15x15 intersections). The winner is the first player to get an unbroken row of five stones horizontally, vertically, or
diagonally.

We now have an uncompleted game, that is to say, yet no one won. You are required to tell us that whether the next player
could win within one step or not.
 

Input
The input consists of multiple test cases. The first line of input contains an integer T, which is the number of test cases.

Each test case is a 15 * 15 go board, 'B' represent for a black stone while 'W' for white ones. '.' represents cross with no
stone represented by 0.


[Technical Specification]
T is an integer, and T <= 20.
The number of white stones is either equal or 1 less than the number of black stones.
There is at least ONE '.' in each test case.
Test cases are separated by ONE empty line.
You can assume that black player goes first.
 

Output
For each test case, print a single line containing the result. If the next player could win within one step, display 'YES',
otherwise, display 'NO'.
 

Sample Input
2 ........W...... ..W......W...B. .W....B........ .W.......W..... ..BB....W...... ...B........... ....B........WW ...........B... ....W.......... .W..B.B....WBB. BW........B.W.B ............... W.....BB.W....W B..B.W.BB....B. ........WW..... ...B...W..BBW.. W..WBW..W...B.. ...W..WBW...... .....BWW..B.B.. ..BW.B.B..W.... B..W..WBW...... B......B......W B.B...B....W... ....B.WB...B... B.W............ .....WW...B.... ..B.....B...W.W .W.........WBW. B.............. ..W.B...W..W..B
 

Sample Output
NO YES



先判断要走哪种棋子,然后对能下的地方枚举4对相反方向看能不能连成五子


#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>

using namespace std;

char mapp[20][20];
const int N = 15;

/*八对相反的位置:
(-1,0) (1,0) 上 下
(0,-1) (0,1) 左 右
(-1,-1) (1,1) 左上 右下
(-1,1) (1,-1) 右上 左下
*/
int dir[4][4] = { -1, 0, 1, 0, 0, -1, 0, 1, -1, -1, 1, 1, -1, 1, 1, -1 };

//判断是否出棋盘
bool Isout(int x, int y) {
	if (x < 0 || x >= N || y < 0 || y >= N) {
		return true;
	}
	return false;
}

/*五子相连只有三种情况:
XOOOO,OOOOX,OOXOO
在最左加一子,在最右面加一子,在中间某个地方加一子
然后在上面4对相反的方向上枚举尝试
*/
bool check(int x, int y, char go) {
	int cou;
	for (int i = 0; i < 4; i++) {
		cou = 1;  //要填的棋子占一个

		//方向A
		for (int nx = x + dir[i][0], ny = y + dir[i][1]; !Isout(nx, ny) && mapp[nx][ny] == go; nx += dir[i][0], ny += dir[i][1]) {
			cou++;
		}
		if (cou == 5) break;  //对应XOOOO成功

		//与方向A反向的反向B
		for (int nx = x + dir[i][2], ny = y + dir[i][3]; !Isout(nx, ny) && mapp[nx][ny] == go; nx += dir[i][2], ny += dir[i][3]) {
			cou++;
		}
		if (cou == 5) break;  //如果第一个循环没有进入的话,对应OOOOX成功
				      //如果第一个循环进入了的话,则说明两个方向合在一起成功,对应OOXOO成功
	}
	if (cou == 5) return true;
	return false;
}

int main()
{
	int T;
	scanf("%d", &T);
	while (T--) {
		int cw, cb;  //记录黑白子的数量
		cw = cb = 0;
		for (int i = 0; i < N; i++) {
			scanf("%s", mapp[i]);
			for (int j = 0; j < N; j++) {
				if (mapp[i][j] == 'W') cw++;
				if (mapp[i][j] == 'B') cb++;
			}
		}

		/*题目要求第一步一定是B,并且cw <= cb
		如果cw < cb说明下一步该白子走
		如:
		   B W B ->W
		如果cw == cb说明下一步该黑子走
		如:
		   B W B W ->B 
		*/
		char next = cw < cb ? 'W' : 'B';

		//标记是否有五子相连
		bool flag = false;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (mapp[i][j] == '.' && check(i, j, next)) {
					flag = true;
					break;
				}
			}
			if (flag) break;
		}
		if (flag) {
			puts("YES");
		}
		else {
			puts("NO");
		}
	}
	return 0;
}




深度学习---双层神经网络中矩阵的运算及其含义记录 深度学习---双层神经网络中矩阵的运算及其含义记录神经网络的正向传播与反向传播正向传播第一层的权重矩阵第一层的输入矩阵Z^1^ = W^1^X^1^ + b^1^A^1^ = σ(Z^1^)第二层的权重矩阵第二层的输入矩阵Z^2^ = W^2^A^1^ + b^2^反向传播dz^2^ = A^2^ - Ydw^2^ = 1/n dz^2^A^1T^db^2^ = 1/n np.sum(dz^2... 阅读详情

相关推荐

手把手教你用Zemax优化MTF:从‘离焦平衡球差’到高频像差控制的实战技巧

本文详细介绍了如何使用Zemax优化MTF性能,从基础设置到高级技巧的全流程。通过具体案例,讲解了如何利用离焦平衡球差提升中频MTF,以及识别和控制高频像差的方法,帮助光学设计工程师和学生有效提升成像质量。

weixin_30752699的博客 764

poj 1753 filp game 2015年暑假训练第一题 枚举

题意就是说:翻牌,随便翻到一张牌,其上下左右随他都得翻,看最少用翻几张牌,能够让16张牌全为正或全为负。 这道题有一个大坑,就是每一张牌其实只能翻奇数次,比如翻的顺序为 (3,2)->   (2,2)  ->  (3,2)   = =   (2,2)  是  等价的 故最多翻的个数是16,从0到16一个一个测试,枚举的是翻牌的个数,若全为正或反,则断开枚举,否则一直枚举 最多有C(0,1

sholck222的专栏 229万+

H.264 Profile与Level详解:如何为不同应用场景选择合适的编码配置

本文深入解析了H.264编码标准中的Profile与Level概念,指导开发者如何为不同应用场景选择合适的配置。文章对比了Baseline、Main和High三大Profile的特性与适用场景,并解释了Level如何限定视频的分辨率、帧率与码率上限。通过实战指南,帮助读者在视频通话、在线点播和专业制作等场景中,平衡画质、兼容性与性能,实现高效编码。

rgv2345678的博客 246

USACO Broken Necklace

Broken Necklace You have a necklace of N red, white, or blue beads (3 1 2 1 2 r b b r b r r b r

在风雨中奔跑 16万+

第14.7章 高翔博士最新开源框架Lightning-LM源码解读(七):PoseExtrapolator模块深度剖析,揭秘激光SLAM高频位姿外推核心技术

PoseExtrapolator是Lightning-LM框架中负责高频位姿外推的核心模块,通过融合DR(航位推算)、激光里程计和PGO(位姿图优化)数据实现精准实时定位。模块初始化依赖PGO数据,后续通过DR数据进行高频位姿更新,并利用PGO结果进行误差补偿。关键函数AddDRLocAndExtrapolate处理DR增量位姿,结合速度补偿机制逐步修正误差,保证高频输出的同时提升精度。该模块体现了多传感器融合思想,通过互补性数据(高频DR与低频高精PGO)实现鲁棒定位,代码中使用了SE3位姿表示、互斥锁保

行知SLAM 355

智能测试策略优化:平衡覆盖率、时间和资源

在软件开发过程中,测试是确保软件质量的关键环节。然而,测试工作往往面临着诸多挑战,其中如何在保证测试覆盖率的前提下,合理分配时间和资源是一个核心问题。本文章的目的在于探讨智能测试策略的优化方法,帮助软件测试团队在有限的时间和资源条件下,实现尽可能高的测试覆盖率。文章的范围涵盖了智能测试策略的核心概念、算法原理、数学模型、实际应用案例以及相关工具和资源等方面。本文将按照以下结构进行组织:首先介绍智能测试策略优化的背景和相关概念,包括核心术语和缩略词的定义;

AIGC应用创新大全的博客 624

[sicily online]1048. Inverso

Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description The game of ‘Inverso’ is played on a 3x3 grid of colored fields (each field is either black or white). Each field is numbered a

qiuchenl的专栏 1676

姿态传感器/陀螺仪之IIS2DLPC 应用驱动程序设计

* 转换为°C单位 (参考温度为25°C,灵敏度为16 LSB/°C) */

corlin6688的博客 225

POJ  1753  Flip Game

Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14504 Accepted: 6218 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each o

算法之道 21万+

【气候极端指数】MATLAB计算各种气候极端指数

简介各类气候极端指数,及其MATLAB计算代码

WW、forever的博客 4922

【中科院一区Top-源码复现】Day-ahead photovoltaic power forecastingwith multi-source temporal-featureconvoluti

【中科院一区Top-源码复现】Day-ahead photovoltaic power forecastingwith multi-source temporal-featureconvoluti

744

8 reasons I accepted your article

Journal editors reveal the top reasons a manuscript gets published By Elizabeth Zwaaf     Posted on 15 January 2013 http://www.elsevier.com/connect/8-reasons-i-accepted-your-article Pet

1022

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

hdu2699

Five in a Row Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 364    Accepted Submission(s): 159 Problem Description The ACM Team of WH

active2489595970的博客 375

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

每日一题之 hiho 204 Five in a Row

题目1 : Five in a Row 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Five in a Row is a game played on a 15x15 go board. Black and White take turns to place a stone of their color in an empty spot. The win...

城南花开的专栏 495

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Five in a Row

题目1 : Five in a Row 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Five in a Row is a game played on a 15x15 go board. Black and White take turns to place a stone of their color in an empty spot. The win...

weixin_38970751的博客 445

CodeForces - 825B Five-In-a-Row

Five-In-a-Row 题目链接:点击这里 题意:         Alice and Bob在下五子棋,Alice用X,Bob用O。现在轮到Alice下了,判断Alice再下一子是否能赢。 题解:   再下一子能连成五子一共有5种情况。遍历棋盘,从中截取连续的5个格,判断是否为5种情况之一。截取方式一共有4种,分别是横向截取,纵向截取,右上截取,右下截取。其中斜向截取又

哇-WA 的博客 365

CodeForces - 825B Five-In-a-Row(棋盘模拟)

题目大意:给你一个五子棋棋局,让你找一下是不是可以接下来下一个子就赢。

薛崇祥的博客 573

HDU 2699 Five in a Row (搜索)

题意: 问下一步是否会赢棋。 #include #include #include #include #include #include using namespace std; const int N = 15; char map[N+9][N+9]; int dx[]={0,0,-1,1,-1,1,-1,1}; int dy[]={-1,1,0,0,-1,1,1,-1}; b

binwin20 729

Codeforces 825 B Five-In-a-Row

题目地址:http://codeforces.com/contest/825/problem/B 题意:五子棋,判断下一步X能不能赢 思路:直接暴搜,遍历每个点判断各种情况(PS,这是我写过最乱的代码,因为忘记考虑有两种斜的情况,被hack了,然后就不想改代码了)

不要錯過才珍惜 388

2016蓝桥杯省赛C/C++B组7题剪邮票 DFS枚举组合情况BFS判联通

剪邮票 如【图1.jpg】, 有12张连在一起的12生肖的邮票。 现在你要从中剪下5张来,要求必须是连着的。 (仅仅连接一个角不算相连) 比如,【图2.jpg】,【图3.jpg】中,粉红色所示部分就是合格的剪取。 请你计算,一共有多少种不同的剪取方法。 请填写表示方案数目的整数。 注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。

EventQueue的博客 6971

poj1006 Biorhythms 边界,坑题

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 125633   Accepted: 39673 Description Some people believe that there are three cycles in a person

EventQueue的博客 2777

hdu计算机学院大学生程序设计竞赛(2015’11)1003 玩骰子

玩骰子 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1017    Accepted Submission(s): 306 Problem Description   Nias与Ains都特别喜欢玩骰子

EventQueue的博客 958

hdu5902 GCD is Funny

GCD is Funny Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 354    Accepted Submission(s): 83 Problem Description Alex has invente

EventQueue的博客 899

蓝桥杯历届试题 PREV-27 蚂蚁感冒 循环暴力模拟

历届试题 蚂蚁感冒   时间限制:1.0s   内存限制:256.0MB      问题描述   长100厘米的细长直杆子上有n只蚂蚁。它们的头有的朝左,有的朝右。   每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/秒。   当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行。   这些蚂蚁中,有1只蚂蚁感冒了。并且在和其它蚂蚁碰面时,会把感冒传染给碰

EventQueue的博客 857
上一篇: hdu1023 Train Problem II 卡特兰数,JAVA大数类
下一篇: 第一次参加蓝桥
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值