CodeForces 606B Testing Robots

时间:2021-04-30 17:38:56

模拟,题意看了一小时

/* ***********************************************
Author :Zhou Zhentao
Email :774388357@qq.com
Created Time :2015/12/15 13:19:28
File Name :main.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; const int maxn=+;
int Map[maxn][maxn];
char s[+];
int ans[+];
int R,C,x,y; bool P(int x,int y)
{
if(x>=&&x<=R)
{
if(y>=&&y<=C)
{
return ;
}
}
return ;
} int main()
{
while(~scanf("%d%d",&R,&C))
{
memset(Map,,sizeof Map);
scanf("%d%d",&x,&y);
Map[x][y]=;
ans[]=;
scanf("%s",s);
int len=strlen(s);
for(int i=; i<len; i++)
{
if(i==len-)
{
int num=;
for(int i=; i<=R; i++)
{
for(int j=; j<=C; j++)
{
if(Map[i][j]==) num++;
}
}
ans[i+]=num;
break;
}
else
{
int NewX,NewY;
if(s[i]=='U')
{
NewX=x-;
NewY=y;
}
else if(s[i]=='D')
{
NewX=x+;
NewY=y;
}
else if(s[i]=='L')
{
NewX=x;
NewY=y-;
}
else if(s[i]=='R')
{
NewX=x;
NewY=y+;
}
if(P(NewX,NewY))
{
x=NewX;
y=NewY;
if(Map[NewX][NewY]==)
{
Map[x][y]=;
ans[i+]=;
}
else ans[i+]=;
}
else ans[i+]=;
}
}
for(int i=; i<=len; i++)
{
printf("%d",ans[i]);
if(i<len) printf(" ");
else printf("\n");
}
}
return ;
}