CodeForces 606 B. Testing Robots(水~)
来源:互联网 发布:古筝模拟软件 编辑:程序博客网 时间:2024/06/05 15:09
Description
一个机器人在n*m的地图上走,初始时在(x,y)点,有一个操作序列s,UDLR分别表示向上下左右走,如果已经在边界且下一步要走出边界机器人会停在边界而不会走出边界,从机器人的初始位置开始,如果他当前位置没有被走过则输出1,走过则输出0,最后输出地图上有多少点没有被机器人走过(不考虑最后一步)
Input
第一行四个整数n,m,x,y分别表示地图行列数和机器人初始坐标,之后为一字符串s表示操作序列(1<=n,m<=500,1<=x<=n,1<=y<=m,1<=|s|<=100000)
Output
前n个整数输出机器人前n个位置是否被走过,最后输出地图上有多少点没有被机器人走过
Sample Input
3 4 2 2
UURDRDRL
Sample Output
1 1 0 1 1 1 1 0 6
Solution
水题,注意要输出的n个0或1不包括最后一步而是以初始位置开始输出
Code
#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define maxn 111111int n,m,x,y,vis[555][555];char s[maxn];int main(){ while(~scanf("%d%d%d%d%s",&n,&m,&x,&y,s)) { memset(vis,0,sizeof(vis)); int len=strlen(s),cnt=1; vis[x][y]=1; printf("1 "); for(int i=0;i<len-1;i++) { if(s[i]=='U'&&x-1>=1)x--; else if(s[i]=='D'&&x+1<=n)x++; else if(s[i]=='L'&&y-1>=1)y--; else if(s[i]=='R'&&y+1<=m)y++; if(!vis[x][y])printf("1 "),cnt++; else printf("0 "); vis[x][y]=1; } printf("%d\n",n*m-cnt); } return 0;}
0 0
- CodeForces 606 B. Testing Robots(水~)
- Codeforces 606B Testing Robots 【模拟】
- Codeforces 606 B Testing Robots【模拟】
- CodeForces 606B Testing Robots【读题题QAQ】
- Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)
- Codeforces Round #335 (Div. 2) B. Testing Robots 模拟
- Codeforces Round #335 (Div. 2) B.Testing Robots
- Codeforces Round #335 (Div. 2) B. Testing Robots (模拟)
- Codeforces Round #335 (Div. 2) B. Testing Robots
- CF 335 div.2-B/606B Testing Robots(读不懂题系列)
- CodeForces - 670B Game of Robots (模拟)水
- Codeforces Round #335 (Div. 2)-Testing Robots(模拟)
- CodeForces 8B - Obsession with Robots
- codeforces 670B Game of Robots
- codeforces 670B Game of Robots
- CodeForces 670B Game of Robots
- 【Codeforces Round 335 (Div 2) B】【模拟】Testing Robots 机器人逐步走 走到矿场就爆炸的最多行走步数
- Codeforces Testing Round #5 B DFS
- some url
- 归并排序经典应用求逆序数
- DB2编目的认识
- 随想录(谈谈软件架构)
- Ajax的组成部分
- CodeForces 606 B. Testing Robots(水~)
- Valid Anagram
- Centos7 安装 RabbitMQ
- 第一行代码-10.2 使用HTTP协议访问网络
- LeetCode-102,103,107,111总结
- 2015年终总结
- 关于索引
- 单例与序列化的那些事儿
- UNIX环境高级编程第十章 信号总结