HDU 5024

题目传送门  http://acm.hdu.edu.cn/showproblem.php?pid=5024

题目大意就是给你一个存在障碍的地图,每次只能旋转90度仅且一次,要你求出最长的通路

其实是一道暴力的水题,哎一开始想着很SB的方法,写了大半天都没写出来,看了看别人的枚举思路后就瞬间茅塞顿开了~~,就是以每个点为转折点,算出齐八个方向转折线路的最大和,然后每个点比较就出现最大值啦><

淼题!!!

#include <iostream>
#include <cstdio>

using namespace std;
const int maxn = 111;
char mp[maxn][maxn];
int n;
int zhi_x[] = {1,-1,0,0};
int zhi_y[] = {0,0,1,-1};
int xie_x[] = {1,1,-1,-1};
int xie_y[] = {-1,1,1,-1};
int get_max(int x,int y) {
    int MAX = 0;
    int b[8] = {0};
    int j = -1;
    for(int i = 0;i < 4;++i) {
        b[++j] = 1;
        int dx = x + zhi_x[i];
        int dy = y + zhi_y[i];
        for(;;dx += zhi_x[i],dy+=zhi_y[i]) {
            if(mp[dx][dy] == ‘.‘) b[j]++;
            else break;
        }
    }
    for(int i = 0;i < 4;++i) {
        b[++j] = 1;
        int dx = x + xie_x[i];
        int dy = y + xie_y[i];
        for(;;dx+=xie_x[i],dy+=xie_y[i]) {
            if(mp[dx][dy] == ‘.‘) b[j]++;
            else break;
        }
    }
    for(int i = 0;i < 4;++i) {
        for(int j = 0;j < 4;++j) {
            if(i!=j) MAX = max(MAX,b[i]+b[j]);
        }
    }
    for(int i = 4;i < 8;++i) {
        for(int j = 4;j < 8;++j) {
            if(i!=j) MAX = max(MAX,b[i]+b[j]);
        }
    }
    return MAX - 1;
}
void get_map() {
    for(int i = 0;i <= n+1;i++)
        for(int j = 0;j <= n+1;j++) mp[i][j] = ‘#‘;
    for(int i = 1;i <= n;++i)
        for(int j = 1;j <= n;++j) scanf(" %c",&mp[i][j]);
}
void get_ans() {
    int ans = 0;
    for(int i = 1;i <= n;++i)
        for(int j = 1;j <= n;++j) if(mp[i][j] == ‘.‘)ans = max(ans,get_max(i,j));
    printf("%d\n",ans);
}
int main() {
    while(scanf("%d",&n)&&n) {
        get_map();
        get_ans();
    }
    return 0;
}
时间: 2024-10-12 19:39:53

HDU 5024的相关文章

hdu 5024 Wang Xifeng&#39;s Little Plot (dfs+暴力)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 194    Accepted Submission(s): 131 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

HDU 5024 Wang Xifeng&#39;s Little Plot (搜索)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 157    Accepted Submission(s): 105 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

hdu 5024 Wang Xifeng&#39;s Little Plot【暴力dfs,剪枝】

2014年广州网络赛的C题,也是水题.要你在一个地图中找出一条最长的路,这条路要保证最多只能有一个拐角,且只能为90度 我们直接用深搜,枚举每个起点,每个方向进行dfs,再加上剪枝. 但是如果直接写的话,那一定会特别麻烦,再加上方向这一属性也是我们需要考虑的方面,我们将从别的地方到当前点的方向编一个号:往右为0,如下图顺时针顺序编号 (往右下方向为1,往下为2......以此类推) 我们知道了当前点的坐标,来到当前点的方向,以及到目前有没有拐弯,这几个属性之后,就可以记忆化搜索了,用一个四维数组

HDU - 5024 Wang Xifeng&#39;s Little Plot

Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qing Dynasty, by Cao Xueqin.

HDU 5024 Wang Xifeng&#39;s Little Plot(2014广州网络赛1003)

写了1h的DFS,简直被自己的代码吓哭了..不过起码还是思路清晰,QUQ~ 说一下题意吧: 题意是求一条最长路,最多能经过一次转弯,并且其角度只能为90度. 拿第一个样例来说:(0,1)->(1,2)->[转弯](2,1) ,所以答案是3. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5024 代码如下: #include<iostream> #include<cstdio> #include<cstring>

HDU 5024 Wang Xifeng&#39;s Little Plot(暴力枚举+瞎搞)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5024 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. Thi

[ACM] HDU 5024 Wang Xifeng&#39;s Little Plot (构造,枚举)

Wang Xifeng's Little Plot Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qin

HDU 5024 Wang Xifeng&#39;s Little Plot (bfs)

Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qing Dynasty, by Cao Xueqin.

HDU 5024 Wang Xifeng&#39;s Little Plot (枚举 + DFS记忆化搜索)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 513    Accepted Submission(s): 338 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

(水DFS) hdu 5024

D - Wang Xifeng's Little Plot Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 5024 Appoint description:  System Crawler  (2015-04-14) Description <Dream of the Red Chamber>(also <The Sto