CodeForces 606B Testing Robots

模拟,题意看了一小时

/* ***********************************************
Author        :Zhou Zhentao
Email         :[email protected]
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;
}
时间: 2024-11-05 06:10:31

CodeForces 606B Testing Robots的相关文章

codeforce 606B Testing Robots

题意:给定一个x*y的矩形,和一个机器人的初始位置(x0,y0).以向下为x轴正方向,向右为y轴正方向.现在要对这个机器人进行多次测试.每次测 试,会在矩形的某个位置有一个矿井.所以一共要进行x*y次测试,每次测试,矿井会出现在一个之前的测试没有出现过的地方,而机器人的初始位置保持不变 (即为(x0,y0)). 每次测试,机器人会沿一个给定的字符串走,字符串只可能包括'L', 'R', 'U', 'D',分别代表向左,向右,向上,向下.当然,如果机器人不能沿所给的方向走(就是走到了边缘),机器人

Codeforces 130A - Testing Pants for Sadness(解题报告)

Testing Pants for SadnessCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 103A Description The average miner Vaganych took refresher courses. As soo

Codeforces Round #335 (Div. 2)

水 A - Magic Spheres 这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了. #include <bits/stdc++.h> using namespace std; #define lson l, mid, o << 1 #define rson mid + 1, r, o << 1 | 1 typedef long long ll; const int N = 1e5 + 5; const int INF = 0x3f3f

Android单元测试与模拟测试详解

测试与基本规范 为什么需要测试? 为了稳定性,能够明确的了解是否正确的完成开发. 更加易于维护,能够在修改代码后保证功能不被破坏. 集成一些工具,规范开发规范,使得代码更加稳定( 如通过 phabricator differential 发diff时提交需要执行的单元测试,在开发流程上就可以保证远端代码的稳定性). 2. 测什么? 一般单元测试: 列出想要测试覆盖的异常情况,进行验证. 性能测试. 模拟测试: 根据需求,测试用户真正在使用过程中,界面的反馈与显示以及一些依赖系统架构的组件的应用测

Codeforces Testing Round #10 B. Balancer

水题,只要遍历一遍,不够平均数的,从后面的借,比平均数多的,把多余的数添加到后面即可,注意数据范围 #include <iostream> #include <vector> #include <cmath> using namespace std; int main(){ int n; cin >> n; vector<long long> a(n); long long sum = 0; for(int i = 0 ; i < n; +

Codeforces Testing Round #10 A. Forgotten Episode

水题,注意数据范围 #include <iostream> using namespace std; int main(){ long long n,a; cin >> n; long long sum =(n*(n+1))>>1; for(int i = 0 ; i < n-1 ; ++i){ cin >>a; sum -=a; } cout<<sum<<endl; } Codeforces Testing Round #10

codeforces ~ 1004 C Sonya and Robots (dp)

C. Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya ha

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(思维题)

Polycarp is preparing the first programming contest for robots. There are nn problems in it, and a lot of robots are going to participate in it. Each robot solving the problem ii gets pipi points, and the score of each robot in the competition is cal

CodeForces 670B Game of Robots

简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #inc