杭电2782

来源:互联网 发布:微杂志免费制作软件 编辑:程序博客网 时间:2024/06/06 01:56

杭电2782

原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=2782
思路:
先留个坑,这样的题夏令营应该不会有,回头再做
代码如下(未通过样例,也有错误,还需更改)

#include <algorithm>#include <cstring>#include <iostream>#include "stdio.h"using namespace std;int a[625][625];int visited[625][625];int direction[4][2] = { 0, 1, -1, 0, 1, 0, 0, -1 };int xs, ys;int ans, d; //分别表示最大值,坐标位置,方向int temp;int m, n, r;void dfs(int x, int y, int tm, int pre){    for (int i = 0; i < 4; i++){        int nx = x + direction[i][0];        int ny = y + direction[i][1];        if (nx >= 0 && nx < m && ny >= 0 && ny < n && a[nx][ny]!=1 && visited[nx][ny] != 1){            visited[nx][ny] = 1; cout << "nx=" << nx << " ny=" << ny << endl;            //temp++;            dfs(nx, ny, ++tm, 0);            if (tm > ans)  { d = i; xs = x; ys = y; ans = tm; }            //temp--;            visited[nx][ny] = 0;        }    }}int main(){    int kase = 1;    while (true){        cin >> m >> n;        if (m == 0 && n == 0) break;        cin >> r;        int tempx, tempy;        memset(a, 0, sizeof(a));        for (int i = 0; i < r; i++){            cin >> tempx >> tempy;            a[tempx][tempy] = 1;        }        ans = 0;        d = 0;        xs = 0, ys = 0;        int flag = 1;        for (int j = 0; j < n; j++){            for (int i = 0; i < m; i++){                if (a[i][j] != 1){                    if (flag == 1) { ans = 1; xs = i; ys = j; flag = 0; }                    memset(visited, 0, sizeof(visited));                    temp = 1;                    visited[i][j] = 1;                    dfs(i, j, 1);                }            }        }        char dire;        if (d == 0) dire = 'E';        if (d == 1) dire = 'N';        if (d == 2) dire = 'S';        if (d == 3) dire = 'W';        cout << "Case " << kase++ << ": " << ans << " " << xs << " " << ys << " " << dire << endl;    }    return 0;}
原创粉丝点击