Codeforces 606B Testing Robots 【模拟】
来源:互联网 发布:运维自动化软件 编辑:程序博客网 时间:2024/05/22 06:33
题意:给定一个n*m的地图(下标从1开始)。在位置(x, y)有一个机器人,现在给该机器人一些指令字符串str,L表示移动到左边的位置,R表移动到右边的位置,U表示移动到下面的位置,D表示移动到上面的位置。已知移动位置超过这个n*m的地图,机器人会在原地停留。机器人体内有一个code会使该机器人爆炸,引爆的条件有两个——机器人移动到有酒的位置或者执行完所有的指令。在n*m个位置上,我们每次选择一个位置(不能重复)并在该位置放上酒,把这作为一次测试。现在问你有多少组测试会使得机器人在执行完k个指令后爆炸(0<=k<=|str|)。假设机器人爆炸后会重置为初始状态。
思路:模拟,统计访问过的位置数cnt。
对于中间移动的位置若已经访问过,则输出0,反之输出1;
对于末尾,若该位置已经访问过,输出n*m-cnt,反之输出n*m-cnt+1。因为酒可以放在访问不到的位置,等到机器人执行完所有|str|个指令就会爆炸。
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define INF 0x3f3f3f3f#define eps 1e-8#define MAXN (100000+10)#define MAXM (100000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;char str[MAXN];bool vis[501][501];int n, m;bool judge(int x, int y){ return x >=1 && x <= n && y >= 1 && y <= m;}int main(){ int x, y; Ri(n); Ri(m); Ri(x); Ri(y); Rs(str); int len = strlen(str); CLR(vis, false); vis[x][y] = true; int cnt = 1; printf("1"); for(int i = 0; i < len; i++) { int xx, yy; switch(str[i]) { case 'U': xx = x-1; yy = y; break; case 'D': xx = x+1; yy = y; break; case 'L': xx = x; yy = y - 1; break; case 'R': xx = x; yy = y + 1; break; } if(!judge(xx, yy)) xx = x, yy = y; printf(" "); if(vis[xx][yy]) { if(i != len-1) printf("0"); else printf("%d", n*m-cnt); } else { cnt++; vis[xx][yy] = true; if(i != len-1) printf("1"); else printf("%d\n", n*m-cnt+1); } //printf(" %d %d\n", xx, yy); x = xx; y = yy; } printf("\n"); return 0;}
0 0
- Codeforces 606B Testing Robots 【模拟】
- Codeforces 606 B Testing Robots【模拟】
- Codeforces Round #335 (Div. 2) 606B Testing Robots(模拟)
- CodeForces 606 B. Testing Robots(水~)
- CodeForces 606B Testing Robots【读题题QAQ】
- Codeforces Round #335 (Div. 2) B. Testing Robots 模拟
- Codeforces Round #335 (Div. 2) B. Testing Robots (模拟)
- Codeforces Round #335 (Div. 2)-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 - 670B Game of Robots (模拟)水
- CF 335 div.2-B/606B Testing Robots(读不懂题系列)
- CodeForces 8B - Obsession with Robots
- codeforces 670B Game of Robots
- codeforces 670B Game of Robots
- CodeForces 670B Game of Robots
- Codeforces Testing Round #5 B DFS
- [Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容
- matplotlib简明教程
- xcode快捷键
- 反向代理服务器的工作原理
- java注释
- Codeforces 606B Testing Robots 【模拟】
- JSP第二篇
- 黑马程序员——IO流
- List集合源码简单分析
- 1. thinkphp (1)
- 启航
- P08 (**) 消除连续重复的列表元素
- PHP autoload性能分析
- Android中killProcess()、System.exit(0)及finish()的区别