HDU - Reversi(dfs+水题)
生活随笔
收集整理的這篇文章主要介紹了
HDU - Reversi(dfs+水题)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:點擊查看
題目大意:下棋游戲,簡單描述一下規則就是,當輪到某一個顏色的棋子操作時,必須在可以吃掉對方棋子的地方下棋,所謂吃掉,就是下棋的地方可以和任意一個己方棋子可以連成一條直線,直線之中至少有一個敵方棋子
題目分析:實在看不懂題意,看看配的圖大概也懂了這個題目的意思。。很簡單的一個dfs,因為棋盤只有8*8,直接暴力枚舉每一個空白位置,然后對于每個空白位置向八個位置搜索,實時更新答案就行
代碼:
#include<iostream> #include<cstdlib> #include<string> #include<cstring> #include<cstdio> #include<algorithm> #include<climits> #include<cmath> #include<cctype> #include<stack> #include<queue> #include<list> #include<vector> #include<set> #include<map> #include<sstream> using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=10;const int b[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,1,-1,-1};char maze[N][N];int sum;void dfs(int x,int y,int k,int step)//行 列 方向 有多少個敵方棋子 {if(x<0||y<0||x>=8||y>=8)return;if(maze[x][y]=='D'){sum+=step;return;}else if(maze[x][y]=='L')dfs(x+b[k][0],y+b[k][1],k,step+1); }int main() { // freopen("input.txt","r",stdin); // ios::sync_with_stdio(false);int w;cin>>w;int kase=0;while(w--){for(int i=0;i<8;i++)scanf("%s",maze[i]);int ans=0;for(int i=0;i<8;i++)for(int j=0;j<8;j++){if(maze[i][j]=='*'){sum=0;for(int k=0;k<8;k++)dfs(i+b[k][0],j+b[k][1],k,0);ans=max(ans,sum);}}printf("Case %d: %d\n",++kase,ans);}return 0; }?
總結
以上是生活随笔為你收集整理的HDU - Reversi(dfs+水题)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CodeForces - 1066B H
- 下一篇: HDU - 3486 Interview