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 ...
随机推荐
- linux 下把Caps_Lock 映射成Ctrl
我用的是debian 7,以前是gnome桌面,系统里就有改变键盘布局的设置.之前gnome 崩了一次,就换成了openbox ,稍微配置了一下也可以很好使用. 可以参考这篇文章 5分钟openbox ...
- PHP集成环境自定义设置PHP版本,同时运行多个php版本,700个PHP版本随时切换,一键开启常用模块。
本文采用我自己开发的纯绿色版WAMP环境(我将这个WAMP环境命名为PHPWAMP) (PHPWAMP默认集成VC,不需要单独安装) 那么什么是WAMP环境?WAMP这个词是什么意思? Windows ...
- 实体类转Json的2种方法
首先申明所需jar包: ezmorph-1.0.6.jar jackson-all-1.7.6.jar jsoup-1.5.2.jar 一.创建一个实体类Emp. package com.hyx.en ...
- USACO 3.3 A Game
A GameIOI'96 - Day 1 Consider the following two-player game played with a sequence of N positive int ...
- Android Studio利用异步任务AsyncTask发送post请求获取json数据
syncTask,是Android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以通过接口实现UI进度更新),最后反馈执行的结果给UI主 ...
- yarn计算一个节点容量及其配置项
mapred-site.xml mapreduce.map.memory.mb 1536 每个Map Container的大小 mapreduce.reduce.memory.mb 2560 每个Re ...
- C#中的重写和覆盖的区别
#中重写(override)和覆盖(new)的区别 重写用关键字 virtual 修饰的方法,叫虚方法.可以在子类中用override 声明同名的方法,这叫“重写”.相应的没有用virtual修饰的方 ...
- subsequence/subsets/subarray/substring problems
128. Longest Consecutive Sequence hashmap, int up = nums[i], int down, int max 注:访问过的要erase 152. Max ...
- SASS相关
1.安装ruby http://rubyinstaller.org/downloads/ 2.安装SASS gem sources --remove https://rubygems.org/ gem ...
- 自定义实现IEnumerable
Demo: http://files.cnblogs.com/files/georgeHeaven/Demo.IEnumerable.rar 一.使用场景 在开发过程中,经常需要使用foreach来循 ...