zoj 1019 Illusive Chase --- dfs
来源:互联网 发布:音乐播放器软件下载 编辑:程序博客网 时间:2024/04/28 22:25
永远都看不清楚nx ny
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define inf 0x3f3f3f3fusing namespace std;int dx[]={0,0,-1,1};int dy[]={-1,1,0,0};struct node{ int a,b; char dir;}op[10010];int t,n,m,cnt,mp[105][105],ans;char s[10];int dfs(int x,int y,int step){ int nx,ny,i,aa,bb,flag; if(step==cnt) return 1; aa=op[step].a; bb=op[step].b; for(i=aa;i<=bb;i++) { switch(op[step].dir) { case 'L':nx=x;ny=y-i;break; case 'R':nx=x;ny=y+i;break; case 'U':nx=x-i;ny=y;break; case 'D':nx=x+i;ny=y; } if(nx<0||nx>=n||ny<0||ny>=m) continue; // printf("i:%d x;%d y:%d nx:%d ny:%d\n",i,x,y,nx,ny); flag=1; if(op[step].dir=='D') { for(int j=x;j<=nx;j++) { if(mp[j][y]) { flag=0; break; } } } else if(op[step].dir=='R') { for(int j=y;j<=ny;j++) { if(mp[x][j]) { flag=0; break; } } } else if(op[step].dir=='U') { for(int j=x;j>=nx;j--) { if(mp[j][y]) { flag=0; break; } } } else if(op[step].dir=='L') { for(int j=y;j>=ny;j--) { if(mp[x][j]) { flag=0; break; } } } if(flag) { if(dfs(nx,ny,step+1)) return 1; } } return 0;}int main(){ int i,j; scanf("%d",&t); while(t--) { memset(mp,0,sizeof mp); scanf("%d%d",&n,&m); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&mp[i][j]); } } cnt=0; while(scanf("%d%d",&op[cnt].a,&op[cnt].b)&&(op[cnt].a||op[cnt].b)) { scanf("%s",s); // printf("op:%c\n",s[0]); op[cnt].dir=s[0]; cnt++; } ans=0; for(i=0;i<n;i++) { for(j=0;j<m;j++) if(!mp[i][j]) if(dfs(i,j,0)){ ans++; // printf("i:%d j:%d\n",i,j); } } printf("%d\n",ans); } return 0;}
0 0
- zoj 1019 Illusive Chase --- dfs
- POJ 1071 && ZOJ 1019 Illusive Chase (dfs)
- zoj 1019 Illusive chase
- zoj 1019 Illusive Chase
- zoj 1019 Illusive Chase
- zoj 1019 Illusive Chase
- POJ 1071 & HDU 1364 & ZOJ 1019 Illusive Chase(DFS)
- ZOJ 1019 Illusive Chase
- POJ1071 Illusive Chase(DFS)
- hdu 1364 Illusive Chase (dfs)
- hdu Illusive Chase 1364 dfs
- POJ 1071Illusive Chase(DFS)
- 【DFS】HDU 1364 && POJ 1071 Illusive Chase
- ZOJ1019 Illusive Chase
- poj 1071 Illusive Chase
- hdu 1364 Illusive Chase
- POJ 1071 Illusive Chase 笔记
- poj1071 && zoj1019Illusive Chase(dfs)
- 中文 “着”与“著”
- android代码混淆及打包相关
- 汇编总结-第二部分_2_数据处理
- cocos2d-x 纹理研究
- EcShop之路-Smarty
- zoj 1019 Illusive Chase --- dfs
- JSP 500页面的异常信息
- Javascript模块化编程
- 汇编总结-第二部分_3_使用函数
- 技术连接收藏
- GNU ARM汇编--(十七)u-boot的makefile和mkconfig解读
- CDN技术入门教程
- object—c 代理 协议 委托 数据源 概念
- matlab 算术编码