HDU 2821 Pusher
来源:互联网 发布:ovd后缀名是什么软件 编辑:程序博客网 时间:2024/06/06 07:08
dfs
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <vector>#include <map>#include <queue>#include <ctime>#include <set>#define ll long long#define MK make_pair#define PB push_back#define SZ(x) ((int)(x).size())#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )using namespace std;char g[30][30];string op="UDLR",ansop;int sum=0,a[30][30],n,m,ansx,ansy,nn,dx[]={-1,1,0,0},dy[]={0,0,-1,1};bool ok;inline bool in(int x,int y){ return x<n&&x>=0&&y<m&&y>=0;}void dfs(int x,int y,int cnt,int ind,string opp){ if(!cnt){ nn=ind; ok=true; ansop=opp; return; } if(ok) return; for(int i=0;i<4;i++){ int nx=x+dx[i],ny=y+dy[i]; if(!in(nx,ny)||a[nx][ny]) continue; while(in(nx,ny)&&!a[nx][ny]) nx+=dx[i],ny+=dy[i]; if(!in(nx,ny)) continue; int t=a[nx][ny]; a[nx][ny]=0; if(!in(nx+dx[i],ny+dy[i])) dfs(nx,ny,cnt-t,ind+1,opp+op[i]); else{ a[nx+dx[i]][ny+dy[i]]+=t-1; dfs(nx,ny,cnt-1,ind+1,opp+op[i]); } a[nx][ny]=t; if(in(nx+dx[i],ny+dy[i])) a[nx+dx[i]][ny+dy[i]]-=t-1; }}int main(){#ifndef ONLINE_JUDGE freopen("a.in","r",stdin); freopen("a.out","w",stdout);#endif while(cin>>m>>n){ for(int i=0;i<n;i++) scanf("%s",g[i]); sum=0;ansop=""; for(int i=0;i<n;i++) for(int j=0;j<m;j++){ if(g[i][j]=='.') a[i][j]=0; else a[i][j]=g[i][j]-'a'+1; sum+=a[i][j]; } ok=false; for(int i=0;i<n;i++){ for(int j=0;j<m;j++) if(g[i][j]=='.'){ dfs(i,j,sum,0,""); if(ok){ ansx=i;ansy=j; break; } } if(ok) break; } cout<<ansx<<endl; cout<<ansy<<endl; cout<<ansop<<endl; } return 0;}
- HDU 2821 Pusher
- DFS-hdu-2821-Pusher
- HDU 2821 Pusher
- HDU-2821-Pusher(DFS)
- HDU 2821 Pusher
- HDU 2821 Pusher
- HDU 2821--Pusher
- hdu 2821 Pusher DFS
- HDU 2821 Pusher
- hdu 2821 pusher 4.3.7
- hdu 2821 Pusher 附几组数据
- hdu 2821 Pusher (dfs)
- hdu 2821 Pusher(dfs)
- hdu 2821 Pusher (水dfs)
- 【搜索】 HDU 2821 Pusher DFS
- HDU 2821Pusher(DFS )
- hud-2821-Pusher
- (HDU 2821)Pusher DFS + 在一个方向上可以移动多位
- hdu - 1087 - Super Jumping! Jumping! Jumping!
- 【双端队列】滑动的窗户 window
- Building a Dynamic UI with Fragments
- 遍历序列与二叉树的复原
- MYSQL高效率地装载数据解决方案
- HDU 2821 Pusher
- Exchange Server 2013架构设计示例一
- 多线程编程技术(第十四课)
- Exchange Server 2013架构设计示例二
- 异步编程技术(第十五课)
- Eclipse+Maven配置
- Using the Support Library
- Creating a Fragment
- ADO.NET概述(第十六课)