HDU 3368 Reversi (暴力,DFS)
题意:给定一个8*8的棋盘,然后要懂黑白棋,现在是黑棋走了,问你放一个黑子,最多能翻白子多少个。
析:我是这么想的,反正才是8*8的棋盘,那么就暴吧,反正不会超时,把每一个格能暴力的都暴力,无非是上,下,左,右,左上,左下,右上,右下,
然后都试试就好了。不过懂点黑白棋的还是好做一点。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <algorithm> using namespace std;
const int maxn = 10 + 5;
const int dr[] = {0, 0, 1, -1, 1, -1, -1, 1};
const int dc[] = {1, -1, 1, -1, -1, 1, 0, 0};
char s[maxn][maxn];
int vis[maxn][maxn]; int dfs(int x, int y, int r, int c){
int xx = r + x;
int yy = c + y;
if(xx < 0 || yy < 0 || xx > 7 || yy > 7) return 0;
vis[x][y] = 1;
if(s[xx][yy] == 'D' || s[xx][yy] == '*') return 0;
if(s[xx][yy] == 'L' && !vis[xx][yy]) return 1 + dfs(xx, yy, r, c);
else if(s[xx][yy] == 'L' && vis[xx][yy]) return dfs(xx, yy, r, c);
return 0;
} int main(){
int n;
cin >> n; for(int kase = 1; kase <= n; ++kase){
memset(vis, 0, sizeof(vis));
// int ans = 0;
for(int i = 0; i < 8; ++i)
scanf("%s", s[i]);
int ans = 0; for(int i = 0; i < 8; ++i){
for(int j = 0; j < 8; ++j){
int cnt = 0;
memset(vis, 0, sizeof(vis));
if(s[i][j] == '*'){ for(int k = 0; k < 8; ++k){
int xx = i, yy = j;
bool ok = false;
while(xx >= 0 && xx < 8 && yy >= 0 && yy < 8){
if(s[xx][yy] == 'D'){ ok = true; break; }
xx += dr[k];
yy += dc[k];
if(s[xx][yy] == '*') break;
}
if(ok){ cnt += dfs(i, j, dr[k], dc[k]); } }
}
ans = max(ans, cnt);
}
} printf("Case %d: %d\n", kase, ans);
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
const int maxn = 200 + 5;
const int dr[] = {0, 0, 1, -1, 1, -1, -1, 1};
const int dc[] = {1, -1, 1, -1, -1, 1, 0, 0};
char s[10][10]; int dfs(int i, int j, int r, int c){
if(i < 0 || j < 0 || i > 7 || j > 8) return -1000;
else if(s[i][j] == '*') return -1000;
else if(s[i][j] == 'D') return 0;
else return 1 + dfs(i+r, c+j, r, c);
} int main(){
int T;
cin >> T;
for(int kase = 1; kase <= T; ++kase){
for(int i = 0; i < 8; ++i)
scanf("%s", s[i]);
int ans = 0;
for(int i = 0; i < 8; ++i)
for(int j = 0; j < 8; ++j)
if(s[i][j] == '*'){
int cnt = 0;
for(int k = 0; k < 8; ++k)
cnt += max(0, dfs(i+dr[k], j+dc[k], dr[k], dc[k]));
ans = max(ans, cnt);
} printf("Case %d: %d\n", kase, ans); }
return 0;
}
HDU 3368 Reversi (暴力,DFS)的更多相关文章
- HDU 3368 Reversi
http://acm.hdu.edu.cn/showproblem.php?pid=3368 题意:模拟黑白棋,下一步黑手最大可以转化多少个白旗 分析:暴力 原先的思路是找到D然后遍历其八个方向,直到 ...
- hihoCoder 1185 连通性·三(Tarjan缩点+暴力DFS)
#1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出 ...
- Strange Country II 暴力dfs
这题点的个数(<=50)有限, 所以可以纯暴力DFS去搜索 //#pragma comment(linker, "/STACK:16777216") //for c++ Co ...
- HDU 1269 迷宫城堡(DFS)
迷宫城堡 Problem Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的 ...
- HDU 1045 Fire Net(DFS)
Fire Net Problem Description Suppose that we have a square city with straight streets. A map of a ci ...
- HDU - 5877 Weak Pair (dfs+树状数组)
题目链接:Weak Pair 题意: 给出一颗有根树,如果有一对u,v,如果满足u是v的父节点且vec[u]×vec[v]<=k,则称这对结点是虚弱的,问这棵树中有几对虚弱的结点. 题解: 刚开 ...
- HDOJ(HDU).2660 Accepted Necklace (DFS)
HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些 ...
- HDOJ(HDU).1045 Fire Net (DFS)
HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...
- HDOJ(HDU).1241 Oil Deposits(DFS)
HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
随机推荐
- 笔记:C 编译过程
笔记:C 编译过程 参考了 编译器的工作过程 1 C 编译过程 配置 确定标准库和头文件位置 确定依赖关系 头文件的预编译 预处理 编译 连接 F4NNIU 2018-06-12 编译器的工作过程 h ...
- tomcat启动报错:Bean name 'XXX' is already used in this <beans> element
如题,tomcat容器启动时加载spring的bean,结果报错如下: 六月 28, 2017 9:02:25 上午 org.apache.tomcat.util.digester.SetProper ...
- 有关Botton的用法(二)
关于设置listener监听onClicked事件的步骤分析 Steps: 1.tell android you are interested in listening to a button cli ...
- 如何设计并使用FireMonkeyStyle
如何设计并使用FireMonkeyStyle FireMonkey使用Style来控制控件的显示方式. 每个控件都有一个StyleLookup属性,FireMonkey就是通过控件的这个属性来在当前窗 ...
- 【转】使用Jmeter测试Webservice简单示例
1.webservice 先简单开发webservice,参考文档 http://www.cnblogs.com/xwdreamer/archive/2011/12/07/2296914.html w ...
- git的分布式和集中式
当然,Git的优势不单是不必联网这么简单,后面我们还会看到Git极其强大的分支管理,把SVN等远远抛在了后面.
- linnx常用命令学习
ll命令就相当于ls -l. [-][rwx][r-x][r--] [-] 代表这个文件名为目录或文件(d为目录-为文件) [rwx]为:拥有人的权限(rwx为可读.可写.可执行) [r-x]为:同群 ...
- python学习(六) 抽象
6.1 懒惰即美德 斐波那契数列: >>> fabs = [0, 1]>>> for i in range(8): fabs.append(fabs[-1] + f ...
- 如何成为java架构师(转载)
链接:https://www.zhihu.com/question/29031276/answer/54631312 来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1 ...
- zabbix短信监控
[ ] zabbix-短信报警(参考http://hanyun.blog.51cto.com/1060170/1604918 ) [ ] zabbix-电话报警(参考http://dl528888.b ...