Reversi

Time Limit: 5000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1226    Accepted Submission(s): 258
Problem Description
Reversi, also called Othello, is a two-sided game.
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?

 
Input
The first line contains one integer T representing the number of test cases.
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.
 
Output
For each test case, in one line print the case number and the largest number of light pieces the dark player can turn over. If he can’t put one piece in any position, then print 0.
Please follow the format of the sample output.
 
SampleInput
3
********
********
********
***LD***
***DL***
********
********
******** ********
********
**DLL***
**DLLL**
**DLD***
********
********
******** ********
********
*D******
*DLLD***
***LL***
**D*D***
********
********
 
SampleOutput
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(暴力枚举)的更多相关文章

  1. BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定

    题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...

  2. HDU 3368 Reversi (暴力,DFS)

    题意:给定一个8*8的棋盘,然后要懂黑白棋,现在是黑棋走了,问你放一个黑子,最多能翻白子多少个. 析:我是这么想的,反正才是8*8的棋盘,那么就暴吧,反正不会超时,把每一个格能暴力的都暴力,无非是上, ...

  3. HDU 3368 Reversi

    http://acm.hdu.edu.cn/showproblem.php?pid=3368 题意:模拟黑白棋,下一步黑手最大可以转化多少个白旗 分析:暴力 原先的思路是找到D然后遍历其八个方向,直到 ...

  4. HDU 4462(暴力枚举)

    因为题目当中的k比较小k <= 10,所以可以直接枚举,题目里面由两个trick, 一个是如果每个点都可以放稻草人的话,那么答案是0, 另外一个就是如果可以放稻草人的点不用被照到.知道了这两个基 ...

  5. HDU 6351暴力枚举 6354计算几何

    Beautiful Now Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  6. HDU 6638 - Snowy Smile 线段树区间合并+暴力枚举

    HDU 6638 - Snowy Smile 题意 给你\(n\)个点的坐标\((x,\ y)\)和对应的权值\(w\),让你找到一个矩形,使这个矩阵里面点的权值总和最大. 思路 先离散化纵坐标\(y ...

  7. hdu 1172 猜数字(暴力枚举)

    题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...

  8. hdu 4445 Crazy Tank (暴力枚举)

    Crazy Tank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. HDU - 1248 寒冰王座 数学or暴力枚举

    思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...

  10. 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 ...

随机推荐

  1. Ubuntu下JDK+Tomcat+MySql环境的搭建

    主机在阿里云上,所以网络的配置都省了,只剩下软件的安装和配置 1.安装mysql 1.1 apt-get install mysql-server-5.5 安装过程中,有两次提示输入 mysql 的  ...

  2. 通过Shell脚本读取properties文件中的参数时遇到\r换行符的问题

    今天在编写微服务程序启动脚本的时候,遇到一个比较奇葩的问题,下面给出具体描述: 目标:通过读取maven插件打包时生成的pom.properties文件,获取里面的应用名称和应用版本号,然后拼接得到s ...

  3. C语言之分支结构 if(一)

    一 程序的三种基本结构 顺序结构:程序从上往下依次执行,这个叫顺序结构 分支结构:有选择的执行或者不执行某段代码 循环结构:重复的执行某段代码 二 分支结构之if 最简单的俩种用法 (tips: if ...

  4. Java排序方法sort的使用详解

    对数组的排序: //对数组排序 public void arraySort(){ int[] arr = {1,4,6,333,8,2}; Arrays.sort(arr);//使用java.util ...

  5. C++程序设计与语言(特别版) -- 导论

    前言 刚开始的时候只学习了一些简单的C++语法知识,当C++不再是一门学科需要考试的时候,就想重新把C++捡回来,希望从中学习到一点思想性的东西而不再是一些语法性的东西. 下面都是一些参考书目的摘抄或 ...

  6. ASP.NET CORE 1.0 初次接触

    vs2015 update3 升级后,可以创建asp.net core 1.0 的web应用了, 默认模版,发布到指定文件夹 服务器上需要安装 DotNetCore.1.0.0-WindowsHost ...

  7. Singleton Pattern(单例模式)

    1.简介 单例模式,顾名思义,即在整个系统中,类的实例对象只有一个. 单例模式具有以下特点: 单例类只能有一个实例 单例类必须自己创建自己的唯一实例 单例类必须给所有其他对象提供这一实例 2.实现 其 ...

  8. 【Android-UI】包含多个子View时触发父节点的焦点事件

    今天遇到个问题: 在 LinearLayout 中添加了好几个其他视图 View 之后,点击时不能获得焦点,导致绑定的 onClick 事件不能触发. 解决办法: 对 LinearLayout 添加属 ...

  9. C++之指针例题解析

    看了挺长一段时间的C了,基本上是把基础语法过关了,偶然遇见一个C++的面试题,分析一下,作为一段时间的打卡. 代码在编译器里边打一下, #include <iostream> using ...

  10. [SOJ] 导游

    Description Mr. G. 在孟加拉国的一家旅游公司工作.他当前的任务是带一些游客去一些遥远的城市.和所有国家一样,一些城市之间有双向道路.每对相邻城市之间都有一条公交路线,每条路线都规定了 ...