zoukankan      html  css  js  c++  java
  • HDU 3386 Reversi

    Reversi

    Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1065    Accepted Submission(s): 435


    Problem Description
    Reversi, also called Othello, is a two-sided game.
    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:
    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?
     

    Input
    The first line contains one integer T representing the number of test cases.
    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.
     

    Output
    For each test case, in one line print the case number and the largest number of light pieces the dark player can turn over. If he can’t put one piece in any position, then print 0.
    Please follow the format of the sample output.
     

    Sample Input
    3
    ********
    ********
    ********
    ***LD***
    ***DL***
    ********
    ********
    ********
    ********
    ********
    **DLL***
    **DLLL**
    **DLD***
    ********
    ********
    ********
    ********
    ********
    *D******
    *DLLD***
    ***LL***
    **D*D***
    ********
    ********
     

    Sample Output
    Case 1: 1
    Case 2: 3
    Case 3: 0
     

    Source
     

    Recommend
    lcy
     
    思路:DFS,但是模拟既可以
    题目难在题意啊,语言啊
     
    代码:
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    char map[10][10];
    int t;
    int maxn;
    int sum;
    int move[8][2] = {1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,1,-1,-1};
    bool yescan(int x,int y)
    {
        if(x < 8 && x >= 0 && y < 8 && y >= 0)
            return true;
        return false;
    }
    void DFS(int xx,int yy)
    {
        for(int i = 0;i < 8;i ++)
        {
            int flag = 0;
            int x = xx + move[i][0];int y = yy + move[i][1];
            while(yescan(x,y) == 1)
            {
                if(map[x][y] == '*')
                    break ;
                if(map[x][y] == 'D')
                {
                    sum += flag;
                    break ;
                }
                if(map[x][y] == 'L')
                {
                    flag ++;
                    x += move[i][0];
                    y += move[i][1];
                }
            }
        }
        return ;
    }
    int main()
    {
        scanf("%d",&t);
        for(int k = 1;k <= t;k ++)
        {
            memset(map,0,sizeof(map));
            for(int i = 0;i < 8;i ++)
               scanf("%s",map[i]);
            maxn = 0;
            printf("Case %d: ",k);
            for(int i = 0;i < 8;i ++)
               for(int j = 0;j < 8;j ++)
               {
                   if(map[i][j] == '*')
                   {
                       sum = 0;
                       DFS(i,j);
                       if(sum > maxn)
                          maxn = sum;
                   }
               }
               printf("%d
    ",maxn);
        }
        return 0;
    }
  • 相关阅读:
    Python2和3版本对str和bytes类型的处理
    使用Fiddle对夜神模拟器进行抓包的设置
    WebSocket 实现链接 群聊(low low low 版本)
    WebSocket 实现链接 发送消息
    Linux文件操作命令
    Linux命令格式
    FastJson
    JSON语法规则
    Mybatis resultMap支持继承
    Mybatis在xml文件中处理大于号小于号的方法
  • 原文地址:https://www.cnblogs.com/GODLIKEING/p/3352853.html
Copyright © 2011-2022 走看看