CodeForces 606B Testing Robots

模拟,题意看了一小时

/* ***********************************************
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=500+10;
int Map[maxn][maxn];
char s[100000+10];
int ans[100000+10];
int R,C,x,y;

bool P(int x,int y)
{
    if(x>=1&&x<=R)
    {
        if(y>=1&&y<=C)
        {
            return 1;
        }
    }
    return 0;
}

int main()
{
    while(~scanf("%d%d",&R,&C))
    {
        memset(Map,0,sizeof Map);
        scanf("%d%d",&x,&y);
        Map[x][y]=1;
        ans[0]=1;
        scanf("%s",s);
        int len=strlen(s);
        for(int i=0; i<len; i++)
        {
            if(i==len-1)
            {
                int num=0;
                for(int i=1; i<=R; i++)
                {
                    for(int j=1; j<=C; j++)
                    {
                        if(Map[i][j]==0) num++;
                    }
                }
                ans[i+1]=num;
                break;
            }
            else
            {
                int NewX,NewY;
                if(s[i]=='U')
                {
                    NewX=x-1;
                    NewY=y;
                }
                else if(s[i]=='D')
                {
                    NewX=x+1;
                    NewY=y;
                }
                else if(s[i]=='L')
                {
                    NewX=x;
                    NewY=y-1;
                }
                else if(s[i]=='R')
                {
                    NewX=x;
                    NewY=y+1;
                }
                if(P(NewX,NewY))
                {
                    x=NewX;
                    y=NewY;
                    if(Map[NewX][NewY]==0)
                    {
                        Map[x][y]=1;
                        ans[i+1]=1;
                    }
                    else ans[i+1]=0;
                }
                else ans[i+1]=0;
            }
        }
        for(int i=0; i<=len; i++)
        {
            printf("%d",ans[i]);
            if(i<len) printf(" ");
            else printf("\n");
        }
    }
    return 0;
}

 

posted @ 2015-12-15 20:18  Fighting_Heart  阅读(271)  评论(0编辑  收藏  举报