天天看點

Hud 5024 Wang Xifeng's Little Plot(2014 ACM/ICPC Asia Regional Guangzhou Online)

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=5024

題目的意思就是 :找隻能拐一個90度的彎的最長路。。直接模拟就好。。

記得網賽的時候,對這個題的題意還是比較有争議的。。。

貼下最主要的題意:if there was a turn, that turn must be ninety degree.

如果有彎,那必須是90度的彎。。這一點十分重要。。

那麼這就好弄了。。枚舉'.'位置的8個方向。。垂直組合找到最大的就好。代碼簡單,思路清晰。。

Code:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
using namespace std;

const int  N = 105;
char map[N][N];
int n;

int find(int x, int y)
{
    int _0 = 0, _1 = 0, _2 = 0, _3 = 0, _4 = 0, _5 = 0, _6 = 0, _7 = 0;
    int xx = x, yy = y;
    while(map[xx][yy] == '.' && xx >= 1) _0 ++, xx --;
    xx = x; yy = y;
    while(map[xx][yy] == '.' && xx >= 1 && yy <= n) _1 ++, xx --, yy ++;
    xx = x; yy = y;
    while(map[xx][yy] == '.' && yy <= n) _2 ++, yy ++;
    xx = x; yy = y;
    while(map[xx][yy] == '.' && xx <= n && yy <= n) _3 ++, xx ++, yy ++;
    xx = x; yy = y;
    while(map[xx][yy] == '.' && xx <= n) _4 ++, xx ++;
    xx = x; yy = y;
    while(map[xx][yy] == '.' && xx <= n && yy >= 1) _5 ++, xx ++, yy --;
    xx = x; yy = y;
    while(map[xx][yy] == '.' && yy >= 1) _6 ++, yy --;
    xx = x; yy = y;
    while(map[xx][yy] == '.' && xx >= 1 && yy >= 1) _7 ++, xx --, yy --;
//    cout << _0 << _1 << _2 << _3 << _4 << _5 << _6 << _7 << endl;
    int ans = 0;
    if(_0 + _2 - 1> ans) ans = _0 + _2 - 1;
    if(_1 + _3 - 1> ans) ans = _1 + _3 - 1;
    if(_2 + _4 - 1> ans) ans = _2 + _4 - 1;
    if(_3 + _5 - 1> ans) ans = _3 + _5 - 1;
    if(_4 + _6 - 1> ans) ans = _4 + _6 - 1;
    if(_5 + _7 - 1> ans) ans = _5 + _7 - 1;
    if(_6 + _0 - 1> ans) ans = _6 + _0 - 1;
    if(_7 + _1  -1> ans) ans = _7 + _1 - 1;
    return ans;
}
int main()
{
    while(scanf("%d", &n) && n){
        getchar();
        for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= n; j ++)
            scanf("%c", &map[i][j]);
            getchar();
        }
        int ans = -1;
        for(int i = 1; i <= n; i ++){
            for(int j = 1; j <= n; j ++)
            if(map[i][j] == '.'){
                ans = max(ans, find(i, j));
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
           

最近狀态不好,希望慢慢的調整過來。。我也不知道為什麼會出現這種感覺。。

繼續閱讀