记录编号 |
121476 |
评测结果 |
AAAAAAAAAA |
题目名称 |
不听话的机器人 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.723 s |
提交时间 |
2014-09-19 21:59:55 |
内存使用 |
76.70 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7fffffff;
//==============struct declaration==============
struct groups
{
int to;
int n;
groups(int to=0,int n=0):to(to),n(n){}
bool operator <(const groups &rhs) const
{
return to<rhs.to;
}
};
//==============var declaration=================
const int MAXN=100;
int n,m,row,col,sr,sc;
short int f[1001][MAXN][MAXN][4];
char order[1010][10];
char maps[MAXN][MAXN];
int mvr[]={-1,0,1,0};
int mvc[]={0,1,0,-1};
//==============function declaration============
short int dp(int k,int r,int c,int p);
//==============main code=======================
int main()
{
string FileName="nrobot";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
scanf("%d%d%d%d",&n,&m,&sr,&sc);n--;sr--;sc--;
cin.ignore(10,10);
For(i,0,n)
cin.getline(maps[i],1000);
For(i,1,m)
cin.getline(order[i],20);
/*For(i,0,n)
cout<<maps[i]<<endl;
For(i,1,m)
cout<<order[i]<<endl;*/
memset(f,-1,sizeof(f));
printf("%d",dp(1,sr,sc,0));
#ifdef DEBUG
clock_t End_Time=clock();
cout<<endl<<endl<<"Time Used: "<<End_Time-Start_Time<<endl;
#endif
return 0;
}
//================fuction code====================
short int dp(int k,int r,int c,int p)
{
if (k==m+1)
return 0;
#define ans f[k][r][c][p]
if (ans!=-1)
return ans;
ans=2000;
if (order[k][0]=='L')
{
short int t1=dp(k+1,r,c,p)+1;
short int t2=dp(k+1,r,c,p==0?3:p-1);
return ans=min(t1,t2);
}
if (order[k][0]=='R')
{
short int t1=dp(k+1,r,c,p)+1;
short int t2=dp(k+1,r,c,p==3?0:p+1);
return ans=min(t1,t2);
}
if (order[k][0]=='F')
{
if (r+mvr[p]>=0&&r+mvr[p]<=n&&c+mvc[p]>=0&&c+mvc[p]<=n)
if (maps[r+mvr[p]][c+mvc[p]]!='*')
ans=dp(k+1,r+mvr[p],c+mvc[p],p);
short int t1=dp(k+1,r,c,p)+1;
return ans=min(ans,t1);
}
if (order[k][0]=='B')
{
if (r+mvr[(p+2)%4]>=0&&r+mvr[(p+2)%4]<=n&&c+mvc[(p+2)%4]>=0&&c+mvc[(p+2)%4]<=n)
if (maps[r+mvr[(p+2)%4]][c+mvc[(p+2)%4]]!='*')
ans=dp(k+1,r+mvr[(p+2)%4],c+mvc[(p+2)%4],p);
short int t1=dp(k+1,r,c,p)+1;
return ans=min(ans,t1);
}
}