HDU 1010 && POJ 2110 Tempter of the Bone
来源:互联网 发布:小米相机软件 编辑:程序博客网 时间:2024/04/30 01:25
转载请注明出处:http://blog.csdn.net/a1dark
分析:这题是图论经典DFS遍历题、也是经典的DFS剪枝优化题、以前做过很多遍了、现在切图论又遇到了、果断切掉、唉、这题不仅要奇偶剪枝、还要考虑距离与时间来剪枝、确实是道好题、
#include<stdio.h>#include<string.h>#include<math.h>char map[9][9];int dir[4][2]={1,0,0,1,0,-1,-1,0};int m,n,t;int ex,ey;int flag;void dfs(int x,int y,int cnt){ int i,temp,tx,ty; if(x<1||y<1||x>m||y>n)return; if(x==ex&&y==ey&&cnt==t){ flag=1;return; } temp=(t-cnt)-fabs((double)(x-ex))-fabs((double)(y-ey)); if(temp<0||temp%2)return; for(i=0;i<4;i++){ tx=x+dir[i][0]; ty=y+dir[i][1]; if(map[tx][ty]!='X'){ map[tx][ty]='X'; dfs(tx,ty,cnt+1); if(flag)return; map[tx][ty]='.'; } } return;}int main(){ int sx,sy; while(scanf("%d%d%d",&m,&n,&t)!=EOF){ if(m==0&&n==0&&t==0)break; memset(map,'\0',sizeof(map)); int wall=0; for(int i=1;i<=m;i++){ scanf("%s",map[i]+1); for(int j=1;j<=n;j++){ if(map[i][j]=='S'){ sx=i;sy=j; } if(map[i][j]=='D'){ ex=i;ey=j; } if(map[i][j]=='X') wall++; } } if(n*n-wall<=t){ printf("NO\n");continue; } flag=0; map[sx][sy]='X'; dfs(sx,sy,0); if(flag==0) printf("NO\n"); else printf("YES\n"); } return 0;}
- HDU 1010 && POJ 2110 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- 迷宫 hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(深搜)
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU-1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone
- HDU 1010 - Tempter of the Bone
- 对spring的DI,IOC, AOP概念的理解
- memcached
- BB10 写NDEF消息到NFC tag上
- ORACEL查询初值末值
- Web服务器父与子 Apache和Tomcat区别
- HDU 1010 && POJ 2110 Tempter of the Bone
- KX在线调查问卷系统正式登陆BAE 欢迎来访在线调查问卷
- jquery基础详解
- UIView animateWithDuration 使用详解
- 谷歌浏览器Javascript调试教程
- 【转】让代码审查成为你的团队习惯
- 存储过程简介与应用
- 强连通分支之Tarjan 算法
- 论c&c++