杭电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;}
阅读全文
0 0
- 杭电2782
- 杭电
- 杭电
- 杭电
- 杭电 1234 和 杭电 2115
- 杭电2056之Rectangles 杭电
- 杭电ACM1061Rightmost Digit
- 杭电2099 7.11
- 杭电ACM 1003
- 杭电 ACM 2016
- 杭电ACM1466
- 杭电ACM1003
- 杭电ACM1225
- 杭电ACM2023
- 杭电ACM2602
- 杭电ACM2955
- 杭电ACM3198
- 杭电ACM2028 求教
- OA审批1.0版本工作总结
- [Codeforces 727C] Guess The Array 交互题
- 57 linux内核的i2c设备驱动模型
- 栈、堆和静态区
- php 设计模式 (原型模)
- 杭电2782
- Android中自定义VideoView视频播放器
- C++:堆和栈的概念及区别
- C语言文件操作(入门级)
- Ubuntu中Docker的远程访问
- 读《边城》谈谈自己几个想法
- 浅谈JavaScript在Html页面中的位置
- SQL SERVER 游标多重嵌套的例子
- map的遍历总结