HDU:3368-Reversi(暴力枚举)
Reversi
Total Submission(s): 1226 Accepted Submission(s): 258
Each of the two sides corresponds to one player; they are referred to here as light and dark after the sides of Othello pieces, but "heads" and "tails" would identify them equally as well, so long as each marker has sufficiently distinctive sides.
Originally, Reversi did not have a defined starting position. Later it adopted Othello's rules, which state that the game begins with four markers placed in a square in the middle of the grid, two facing light-up, two pieces with the dark side up. The dark player makes the first move.
Dark must place a piece with the dark side up on the board, in such a position that there exists at least one straight (horizontal, vertical, or diagonal) occupied line between the new piece and another dark piece, with one or more contiguous light pieces between them. In the below situation, dark has the following options indicated by transparent pieces:
After placing the piece, dark turns over (flips, captures) all light pieces lying on a straight line between the new piece and any anchoring dark pieces. All reversed pieces now show the dark side, and dark can use them in later moves—unless light has reversed them back in the meantime. In other words, a valid move is one where at least one piece is reversed.
If dark decided to put a piece in the topmost location (all choices are strategically equivalent at this time), one piece gets turned over, so that the board appears thus:
Now light plays. This player operates under the same rules, with the roles reversed: light lays down a light piece, causing a dark piece to flip. Possibilities at this time appear thus (indicated by transparent pieces):
Light takes the bottom left option and reverses one piece:
Players take alternate turns. If one player cannot make a valid move, play passes back to the other player. When neither player can move, the game ends. This occurs when the grid has filled up, or when one player has no more pieces on the board, or when neither player can legally place a piece in any of the remaining squares. The player with the most pieces on the board at the end of the game wins.
Now after several rounds, it’s dark’s turn. Can you figure out the largest number of light pieces he can turn over?
For each test case, there’re 8 lines. Each line contains 8 characters (D represents dark, L represents light, * represents nothing here).
Every two adjacent cases are separated by a blank line.
Please follow the format of the sample output.
3
********
********
********
***LD***
***DL***
********
********
******** ********
********
**DLL***
**DLLL**
**DLD***
********
********
******** ********
********
*D******
*DLLD***
***LL***
**D*D***
********
********
Case 1: 1
Case 2: 3
Case 3: 0
题目大意:就是黑子要和原来已经在的黑子形成一条水平线或垂直线或斜线,并且在两个黑子之间不能用空格,也不能有其他黑子只能含有白子。这样才能放置,求最多能把多少白子变成黑子。
题解:从白子的八个方向开始搜能放置黑子的位置,然后在判断如果这个位置放置黑子能把多少白子变成黑子。记录最大的数量。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[][];
int dx[]={,,-,,,-,,-};
int dy[]={,,,-,,,-,-};
bool vis[][]; bool ok(int x,int y)
{
if(x>= && x< && y>= && y<) return ;
return ;
} int work(int i,int j)
{
int ans=;
for(int k=;k<;k++)
{
int xx=i;
int yy=j;
int sum=;
while(ok(xx+dx[k],yy+dy[k]))
{
xx+=dx[k];
yy+=dy[k];
if (a[xx][yy]=='L') sum++;
if (a[xx][yy]=='D') break;
if (a[xx][yy]=='*') {sum=; break;}
if (!ok(xx+dx[k],yy+dy[k])){sum=; break;}
}
ans+=sum;
}
return ans;
} int main()
{
int n;
while(~scanf("%d",&n))
{
for(int t=;t<=n;t++)
{
for(int i=;i<;i++)
for(int j=;j<;j++)
cin>>a[i][j];
memset(vis,,sizeof(vis));
int res=;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(a[i][j]=='L')
{
for(int k=;k<;k++)
{
int xx=i+dx[k];
int yy=j+dy[k];
if(a[xx][yy]=='*' && !vis[xx][yy])
{vis[xx][yy]=; res=max(res,work(xx,yy));}
}
}
printf("Case %d: %d\n",t,res);
}
}
return ;
}
HDU:3368-Reversi(暴力枚举)的更多相关文章
- BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定
题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...
- HDU 3368 Reversi (暴力,DFS)
题意:给定一个8*8的棋盘,然后要懂黑白棋,现在是黑棋走了,问你放一个黑子,最多能翻白子多少个. 析:我是这么想的,反正才是8*8的棋盘,那么就暴吧,反正不会超时,把每一个格能暴力的都暴力,无非是上, ...
- HDU 3368 Reversi
http://acm.hdu.edu.cn/showproblem.php?pid=3368 题意:模拟黑白棋,下一步黑手最大可以转化多少个白旗 分析:暴力 原先的思路是找到D然后遍历其八个方向,直到 ...
- HDU 4462(暴力枚举)
因为题目当中的k比较小k <= 10,所以可以直接枚举,题目里面由两个trick, 一个是如果每个点都可以放稻草人的话,那么答案是0, 另外一个就是如果可以放稻草人的点不用被照到.知道了这两个基 ...
- HDU 6351暴力枚举 6354计算几何
Beautiful Now Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- HDU 6638 - Snowy Smile 线段树区间合并+暴力枚举
HDU 6638 - Snowy Smile 题意 给你\(n\)个点的坐标\((x,\ y)\)和对应的权值\(w\),让你找到一个矩形,使这个矩阵里面点的权值总和最大. 思路 先离散化纵坐标\(y ...
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU - 1248 寒冰王座 数学or暴力枚举
思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...
- HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
随机推荐
- php设计模式之抽象工厂模式
之前总结了一下工厂模式,其实准确地说是简单 工厂模式,在它的基础上再进行抽象就可以得到一种新的模式:抽象工厂模式. 专业一点的定义为: 抽象工厂模式(Abstact Factory)是一种常见的软件设 ...
- labview 调用 matlab script的神坑! Error 1050 occurred at LabVIEW
显示变量没有被定义,原因是clear 关键字的问题,去掉即可!!! 未找到 文件路径,定位: 文件路径中不能有中文路径
- Python中的各种装饰器详解
Python装饰器,分两部分,一是装饰器本身的定义,一是被装饰器对象的定义. 一.函数式装饰器:装饰器本身是一个函数. 1.装饰函数:被装饰对象是一个函数 [1]装饰器无参数: a.被装饰对象无参数: ...
- [coding horror] 1 - sum 2
sum 2 描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 对应每个测试案例,输出两个数,小的先输出. codi ...
- SDN理解:SDN现状
目录 - SDN现状 - (一)SDN现状 - SDN诞生的背景 - SDN的介绍 - (二)SDN领域的相关组织和发展现状 - 1.ONF - 2.OpenDaylight - 3. IETF - ...
- >> 关于计算机有符号数的符号拓展(sign extension)问题
这里首先阐述相关规律, 情况为将位数较少的有符号存储空间中取出数据并放入更大有符号存储空间, 如: char → short . 规律: 将原空间符号位重复填充至新空间剩余位. eg.(负数情况, ...
- 在Windows上创建同样的Linux操作环境
在之前的文章中,介绍了我在GNU/Linux图形界面环境下所使用的工具集合.其基本目的是在保证占用最少系统资源的条件下,将电脑操作效率推向极致.这样的工具组合尤如瑞士军刀一般,简洁.高效.功能全面.与 ...
- sort vector - leetcode 新用法
179. Largest Number sort(num.begin(), num.end(), [](int a, int b){ return to_string(a)+to_string(b) ...
- 关于php数组是否要声明
不知道大家有没有这样玩过php数组,正常情况下直接不声明,直接使用数组,会发现输出的与声明后的结果是一样的.
- JavaScript忍者秘籍——驯服线程和定时器
1.定时器和线程 - 设置和清除定时器 JavaScript提供了两种方式,用于创建定时器以及两个相应的清除方法.这些方法都是window对象上的方法. 方法 格式 描述 setTimeout i ...