zoukankan      html  css  js  c++  java
  • poj2056

    寻找向左凸的地方,每个左凸能让S数量-2。上边或下边如果是半个左凸的话则各对应-1

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    using namespace std;
    
    #define MAX_ROW 205
    #define MAX_COLUMN MAX_ROW
    
    int row, column;
    char grid[MAX_ROW][MAX_COLUMN];
    
    void input()
    {
        memset(grid, 0, sizeof(grid));
        for (int i = 0; i < row; i++)
            scanf("%s", grid[i]);
    }
    
    void work()
    {
        int direction = -1;    //1 is right, 0 is left
        int s_cnt = 0;
        int x = 0;
        int y = 0;
        while (grid[x][y] != 'S')
            y++;
        s_cnt++;
        while (x < row)
        {
            if (y != 0 && grid[x][y - 1] == 'S')
            {
                direction = 0;
                while (y > 0 && grid[x][y - 1] == 'S')
                    y--, s_cnt++;
                x++, s_cnt++;
                continue;
            }
            if (y + 1 < column && grid[x][y + 1] == 'S')
            {
                if (direction == -1)
                    s_cnt--;
                if (direction == 0)
                    s_cnt -= 2;
                direction = 1;
                while (y + 1 < column && grid[x][y + 1] == 'S')
                    y++, s_cnt++;
                x++, s_cnt++;
                continue;
            }
            x++, s_cnt++;
        }
        if (direction == 0)
            s_cnt--;
        printf("%d
    ", s_cnt - 1);
    }
    
    int main()
    {
        while (scanf("%d%d", &row, &column), row | column)
        {
            input();
            work();
        }
        return 0;
    }
    View Code
  • 相关阅读:
    长宽广州地区DNS
    修改PHP的memory_limit限制
    适用于Magento的最合适的.htaccess写法
    在magento中如何回复客户的评论
    冲刺!
    冲刺!
    冲刺!
    冲刺!
    冲刺!
    冲刺!
  • 原文地址:https://www.cnblogs.com/rainydays/p/3266998.html
Copyright © 2011-2022 走看看