HDU 3368 Reversi (简单dfs)
来源:互联网 发布:js创建一个数组 编辑:程序博客网 时间:2024/06/05 14:24
题意:跟小时候在电视机上玩过的黑白棋一模一样,于是题也没读便开始做。给你一副棋盘,让你走一步黑棋,尽可能多的吃掉白棋,求吃掉的个数。
思路:一开始想从D开始递归,后来一想不对啊,比如,走的那一步黑棋,可以从多个方向上吃掉白棋,那么从D开始递归会麻烦太多。所以:
从*开始dfs,直到遇上D或者*便停止退出递归,把握好递归方向即可。
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>using namespace std;typedef long long LL;char Map[10][10];int kase, T = 0, ans, Max , res;const int dir[9][2] = { {-1,1},{0,1},{1,1}, {-1,0},{1,0}, {-1,-1},{0,-1},{1,-1},{0,0} //前8个为方向,最后(0,0)纯属充数};struct Node{ int x, y, dirr;};void dfs(int x, int y, int dirr, int Max) { if(dirr == 8) { //初始递归值,八个方向 for(int i = 0; i < 8; ++i) { int xx = x+dir[i][0]; int yy = y+dir[i][1]; if(xx >= 0 && xx < 8 && yy >= 0 && yy < 8) dfs(xx, yy, i, Max); } } if(Map[x][y] == 'D') { res += Max; return ; } if(Map[x][y] == '*') { Max = 0; return ; } if(Map[x][y] == 'L') { int xx = x+dir[dirr][0]; int yy = y+dir[dirr][1]; if(xx >= 0 && xx < 8 && yy >= 0 && yy < 8) dfs(xx, yy, dirr, Max+1); }}int main() { scanf("%d", &kase); while(kase--) { ans = Max = res = 0; for(int i = 0; i < 8; ++i) scanf("%s", Map[i]); for(int i = 0; i < 8; ++i) { for(int j = 0; j < 8; ++j) { if(Map[i][j] == '*') { res = 0; dfs(i, j, 8, 0); ans = max(ans, res); } } } printf("Case %d: %d\n", ++T, ans); }}
0 0
- HDU 3368 Reversi (简单dfs)
- HDU 3368 Reversi
- hdu 3368 Reversi
- HDU 3368 Reversi
- HDU 3368 Reversi
- HDU 3368——Reversi
- HDU:3368-Reversi(暴力枚举)
- Hdu 3368 Reversi(暴力)
- Reversi
- HDU-1213(简单DFS)
- hdu 2660 简单 dfs
- hdu 3274 简单 dfs
- hdu 3290 (简单dfs)
- hdu 1241 简单dfs
- 搜索--HDU简单DFS
- HDU 1181(简单dfs)
- HDU--1241 简单DFS
- HDU 1016 超简单DFS
- setMobileDataEnabled方法不能再被调用 Android L and later
- StackOverflow程序员推荐:每个程序员都应读的30本书
- DS1302+LCD1602=万年历
- 一、搭建移动应用服务器
- Linux Samba 服务器配置
- HDU 3368 Reversi (简单dfs)
- hdu5754各种博弈
- SpringMVC接收复杂集合参数
- Codeforces 435C Cardiogram
- 二叉树的最长/最短路径
- Spring Aop的理解和概念
- dom4j CURD
- AsyncTask和Handler对比
- xml基础概念