【ZOJ浙大校赛19】【模拟】Robot Cleaner I

 题目链接:传送门

【题意】:

一个打扫机器人(说到机器人,恭喜LDU在2019-04-21 Robocup中获得全国冠军,为自己的学校及飞哥感到骄傲)。

然后执行指令,在一个指令条中根据当前格子的4联通即当前格子,用3进制来运算,得到的数字进行执行指令。

所以这个题目就是一个大模拟,上下左右的走(U,D,L,R),同时有一个不工作偷懒(I),还有捡起垃圾(P)。

但是捡起垃圾后会清空当前的格子,对于下一个指令也会改变。

【题解】:

因为捡起垃圾会改变状态,所以把所有标记的位置全部清空。

因为可能会走了一个圈绕回来,如果有标记位会阻碍机器人的行走。

 

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
typedef long long ll;
const int N = 2e5+100;
using namespace std;
int Dir[5][2]={
        {0,1},   //R
        {0,-1}, //L
        {1,0},  //D
        {-1,0}, //U
        {0,0},  //yuan
};
int dir[4][2]={
        {-1,0},//U
   {0,-1},  {0,1},//L.R
        {1,0}//D
};
char Ins[500];
int G[2015][2015];
int G_[2015][2015];
int vis[2015][2015];
int T,n,m;
int Getx(int x,int y){
    int res = 0 ;
    int tmp = 1;
    for(int i=0;i<5;i++){
        int tx = x+Dir[i][0];
        int ty = y+Dir[i][1];
        res = res + G[tx][ty]*tmp;
        tmp = tmp *3;
    }
    return res%243+1;
}
bool check(int x,int y){
    return ( 2<=x&&x<n && 2<=y && y<m );
}
int main()
{
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        ll x,y,k;
        scanf("%lld%lld%lld",&x,&y,&k);
        scanf("%s",Ins+1);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%1d",&G[i][j]);
                vis[i][j] = 0 ;
            }
        }
        int ans = 0;
        while(k--){
            int ch = Getx(x,y);
            if( Ins[ch]=='U'){
                int tx = x +dir[0][0];
                int ty = y +dir[0][1];
                if( G[tx][ty] ==1 || vis[tx][ty]==3 )
                    break;
                else {
                    vis[x][y] ++;
                    x = tx; y = ty;
                }
            }else if( Ins[ch] == 'L'){
                int tx = x +dir[1][0];
                int ty = y +dir[1][1];
                if( G[tx][ty] ==1 || vis[tx][ty]==3 )
                    break;
                else {
                    vis[x][y] ++;
                    x = tx; y = ty;
                }
            }else if( Ins[ch] == 'R'){
                int tx = x +dir[2][0];
                int ty = y +dir[2][1];
                if( G[tx][ty] ==1 || vis[tx][ty]==3 )
                    break;
                else {
                    vis[x][y] ++;
                    x = tx; y = ty;
                }
            }else if( Ins[ch] == 'D'){
                int tx = x +dir[3][0];
                int ty = y +dir[3][1];
                if( G[tx][ty] ==1 || vis[tx][ty]==3 )
                    break;
                else {
                    vis[x][y] ++;
                    x = tx; y = ty;
                }
            }else if( Ins[ch] == 'I'){
                break;
            }else if( Ins[ch] == 'P'){
                if( G[x][y]!=2 ){
                    break;
                }else{
                     ans++;
                    G[x][y] = 0;
                    for(int i=1;i<=n;i++){
                        for(int j=1;j<=m;j++){
                            vis[i][j]=0;
                        }
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值