#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=500+5,M=1e5+10,Z=1e9+7,ms63=1061109567;
int n,m,y,x;
bool e[N][N];
char s[M];
int ans[M];
int main()
{
while(~scanf("%d%d%d%d",&n,&m,&y,&x))
{
MS(e,0);
scanf("%s",s);
int l=strlen(s);
ans[l]=n*m;
for(int i=0;i<l;++i)
{
if(e[y][x]==0)
{
e[y][x]=1;
ans[i]=1;
--ans[l];
}
else ans[i]=0;
if(s[i]=='L')
{
if(x>1)--x;
}
else if(s[i]=='R')
{
if(x<m)++x;
}
else if(s[i]=='U')
{
if(y>1)--y;
}
else//if(s[i]=='D')
{
if(y<n)++y;
}
}
for(int i=0;i<=l;++i)printf("%d ",ans[i]);puts("");
}
return 0;
}
/*
【题意】
给你一个n*m(500*500)的棋盘,初始我们的机器人在(y,x),
然后执行一串上下左右的操作(操作序列s的长度不超过1e5),
如果前方不能走,机器人会不动。
如果前方是矿场,机器人会爆炸。
如果所有序列执行完,机器人也会爆炸。
问你,假如说矿场的位置出现在(1,1)~(n,m)的所有位置各一次。
对于这n*m种情况,输出机器人分别在恰好走[0~strlen(s)]步之后就会爆炸的情况数。
【类型】
模拟
【分析】
对于最终路径上的所有点,
如果这个点是第一次走到,那么在这一步就会爆炸。
如果这个点是第多次走到,之前走到过,现在还在走,说明这里不会爆炸。
地图上最终都没有走过(特殊照顾整个序列都走完然后走到的点)的点,计数到ans[strlen(s)]中。
然后输出答案就好啦
【时间复杂度&&优化】
O(strlen(s))
*/
【Codeforces Round 335 (Div 2) B】【模拟】Testing Robots 机器人逐步走 走到矿场就爆炸的最多行走步数
最新推荐文章于 2024-09-28 09:20:52 发布