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 ...
随机推荐
- 函数sql黑马程序员——SQL常用函数
最近使用开辟的过程中出现了一个小问题,顺便记录一下原因和方法--函数sql ---------------------- ASP.Net+Android+IO开辟S..Net培训.等待与您交流! -- ...
- Linux中的task,process, thread 简介
本文的主要目的是介绍在Linux内核中,task,process, thread这3个名字之间的区别和联系.并且和WINDOWS中的相应观念进行比较.如果你已经很清楚了,那么就不用往下看了. LINU ...
- Java之路——Java初接触
本文大纲 1.Java是什么 2.Java历史 3.Java技术范围 3.1 Java SE平台技术范围 3.2 Java EE技术范围 3.3 Java 体系技术范围 4.总结 1.Java是什么 ...
- js判断移动端与pc端
这里介绍下使用device.js插件来判断移动端设备 地址:https://github.com/matthewhudson/device.js 示例: if(device.mobile()){ wi ...
- Perception(0-1.1)
The perception modules run in the context of the process Cognition. They detect features in the imag ...
- .net在网页中生成二维码和条形码
二维码: 1.下载ThoughtWorks.QRCode.dll文件 2.创建Web项目,添加引用刚才下载的文件 3.在项目中添加aspx窗体,编写代码如下 <%@ Page Language= ...
- 学习AngularJs:Directive指令用法(完整版)
这篇文章主要学习AngularJs:Directive指令用法,内容很全面,感兴趣的小伙伴们可以参考一下 本教程使用AngularJs版本:1.5.3 AngularJs GitHub: http ...
- DW,DM,ODS的区别
数据仓库的重要应用是将不同来源的数据和异构数据通过ETL整合在一起,为决策分析提供支撑,若在同一个数据库中分不同用户,此意义不大:假设所有有用户都在一个数据库里,如果因为某个原因数据库重启,那么会影响 ...
- python爆破zip脚本
最近在提高自己编程能力,拿一些实用的小工具练下.该脚本为python语言,主要涉及模块zipfile,threadings模块. 功能:暴力猜解zip解压密码 #coding: utf-8 impor ...
- Fatal error: Call to undefined function oci_connect()
http://stackoverflow.com/questions/22478387/call-to-undefined-function-oci-connect Whenever you conn ...