2017上海市高校程序设计邀请赛_C
2017-07-03 12:19
204 查看
problem list
C 神奇怪兽在哪里
签到题
要求很宽泛,路径可以重叠
dfs遍历解决
C 神奇怪兽在哪里
要求很宽泛,路径可以重叠
dfs遍历解决
#include <bits/stdc++.h> using namespace std; typedef long long LL ; typedef unsigned long long ULL ; const int maxn = 1000 + 10 ; const int inf = 0x3f3f3f3f ; const int npos = -1 ; const double eps = 1e-20 ; int n, m, si, sj, a[maxn][maxn], v[maxn][maxn]; int dx[4]={-1,0,1,0}; int dy[4]={0,-1,0,1}; char c[maxn], d[4]={'U','L','D','R'}; bool bound(int x, int y){ return (0<x)&&(x<=n)&&(0<y)&&(y<=m); } void dfs(int x, int y){ v[x][y]=1; for(int i=0;i<4;i++){ int nx=x+dx[i]; int ny=y+dy[i]; if(bound(nx,ny) && !a[nx][ny] && !v[nx][ny]){ printf("%c",d[i]); dfs(nx,ny); printf("%c",d[(i+2)%4]); } } } int main(){ // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); while(~scanf("%d %d",&n,&m)){ for(int i=1;i<=n;i++){ scanf("%s",c+1); for(int j=1;j<=m;j++){ a[i][j]=(c[j]=='*'); v[i][j]=0; if('P'==c[j]){ si=i; sj=j; } } } dfs(si,sj); } return 0; }
相关文章推荐
- 2017上海市高校程序设计邀请赛_I
- 2017上海市高校程序设计邀请赛_K
- 2017上海市高校程序设计邀请赛_L
- 2017上海市高校程序设计邀请赛_E
- 2017上海市高校程序设计邀请赛_F
- 2017上海市高校程序设计邀请赛_A
- 2017上海市高校程序设计邀请赛_G
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 (重现)
- 游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 (重现)F. 蚂蚁
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 (重现) Problem D. 萝莉理论计算机科学家
- 上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 C. 神奇怪兽在哪里
- k.计软联谊 「游族杯」上海市高校程序设计邀请赛(数论)
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 A. 足球锦标赛
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 E.章鱼哥没有女朋友
- 2017武汉大学华中地区程序设计邀请赛个人感悟
- 大学生程序设计竞赛暨西南地区高校邀请赛 赛后总结
- 华南理工大学第二届“超级码力”程序设计竞赛暨广东省高校邀请赛
- 2017陕西省大学生程序设计竞赛邀请赛总结!
- “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛-神无月排位赛