URAL 2027 URCAPL, Episode 1 (模拟)
题意:给你一个HxW的矩阵,每个点是一个指令,根据指令进行一系列操作。
题解:模拟
#include<cstdio>
#include<algorithm>
using namespace std; const int maxn = ;
char G[maxn][maxn]; int dx[] = {-,,, };
int dy[] = { ,,,-}; struct pointer
{
int r,c;
int dir;
void Move(){
r += dx[dir];
c += dy[dir];
}
char read(){
return G[r][c];
}
}p; int h,w;
const int up_bound = 1e5;
const int TimeLim = 1e6;
const int MaxN = 1e5+;
int readLim;
int readList[MaxN]; void execute()
{
p.r = p.c = ;
int Register[] = {};
int cur = ;
char op = p.read();
p.dir = ;
int step = ;
int ReadTimes = ;
while(op!='#'){
if('A'<=op&&op<='Z'){
swap(Register[op-'A'],cur);
}else switch(op){
case '^':{
p.dir = ;
break;
}
case '>':{
p.dir = ;
break;
}
case 'v':{
p.dir = ;
break;
}
case '<':{
p.dir = ;
break;
}
case '?':{
if(ReadTimes>=readLim){
cur = readList[readLim-];
}else {
cur = readList[ReadTimes];
ReadTimes++;
}
break;
}
case '!':{
printf("%d\n",cur);
cur = ;
break;
}
case '+':{
cur++;
if(abs(cur)>up_bound){
printf("OVERFLOW ERROR\n");
return;
}
break;
}
case '-':{
cur--;
if(abs(cur)>up_bound){
printf("OVERFLOW ERROR\n");
return;
}
break;
}
case '@':{
if(cur){ p.dir = (p.dir+)%; }
else { p.dir = (p.dir+)%; }
break;
}
}
step++;
if(step>TimeLim) {
printf("TIME LIMIT EXCEEDED\n");
return;
}
p.Move();
if(p.r<||p.r>=h||p.c<||p.c>=w) {
printf("RUNTIME ERROR\n"); return;
}
op = p.read();
}
} int main()
{
scanf("%d%d",&h,&w);
for(int i = ; i < h; i++)
scanf("%s",G[i]);
scanf("%d",&readLim);
for(int i = ; i < readLim; i++){
scanf("%d",readList+i);
}
execute(); return ;
}
URAL 2027 URCAPL, Episode 1 (模拟)的更多相关文章
- URAL 1069 Prufer Code(模拟)
Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without cycles) ...
- URAL(timus) 1280 Topological Sorting(模拟)
Topological Sorting Time limit: 1.0 secondMemory limit: 64 MB Michael wants to win the world champio ...
- URAL 2027 2028 两个有趣的题
这两个题,讲的是有一种奇怪的语言,代码是一种二维的矩阵. 前一个题,是根据所给的要求,写一个简单的解释器. 后一个题,是用那种语言写一个简单的小程序. 挺有意思的,所以在这里纪念一下.顺便那个语言的原 ...
- ural 1218. Episode N-th: The Jedi Tournament
1218. Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Je ...
- 模拟 URAL 1149 Sinus Dances
题目传送门 /* 模拟:找到规律分别输出就可以了,简单但是蛮有意思的 */ #include <cstdio> #include <algorithm> #include &l ...
- URAL 1218 Episode N-th: The Jedi Tournament(强连通分量)(缩点)
Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Jedi Kni ...
- URAL 2046 A - The First Day at School 模拟题
A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- URAL 1404. Easy to Hack! (模拟)
space=1&num=1404">1404. Easy to Hack! Time limit: 1.0 second Memory limit: 64 MB When Vi ...
- URAL 1993 This cheeseburger you don't need 模拟题
This cheeseburger you don't need 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1993 Descrip ...
随机推荐
- FZU - 2218 Simple String Problem(状压dp)
Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...
- 19个很有用的 JavaScript库推荐
流行的 JavaScript 库有jQuery,MooTools,Prototype,Dojo和YUI等,这些 JavaScript 库功能丰富,加上它们众多的插件,几乎能实现任何你需要的功能 然而需 ...
- std::function"函数"对象包装器
语义: 类模板std::function是可调用对象的包装器,可以包装除了类成员之外的所有可调用对象.包括,普通函数,函数指针,lambda,仿函数.通过指定的模板参数,它可以用统一的方式保存,并延迟 ...
- Git 分支管理 创建与合并分支
分支在实际中有什么用呢? 假设你准备开发一个新功能,但是需要两周才能完成,第一周你写了50%的代码,如果立刻提交,由于代码还没写完,不完整的代码库会导致别人不能干活了. 如果等代码全部写完再一次提交, ...
- Web项目开发介绍及实战项目介绍
引言 本系列课程我们将学些Golang语言中的Web开发框架Iris的相关知识和用法.通过本系列视频课程,大家能够从零到一经历一个完整项目的开发,并在课程中了解实战项目开发的流程和项目设涉及的各个模块 ...
- PV、UV、VV、IP是什么意思?
PV.UV.VV.IP作为网站分析中最常见的基础指标,能够从宏观概括性地衡量网站的整体运营状况,也是检测网站运营是否正常的最直观的指标. 1.VV(来访次数/访问次数):VisitView 记录所有访 ...
- 教程 | Linux常用命令大全
Linux常用命令 目录操作命令 ls 命令名称:ls 命令英文原意:list 命令所在路径:/bin/ls 执行权限:所有用户 功能描述:显示目录文件 ls (显示当前目录下文件) ls 目录名 ( ...
- redis之使用
redis之使用 redis ================================= 1.自动分配.你在什么时候用到了自动分配? 答:市场部或运营部招来的新的客户,单条(批量)录入数据的 ...
- 什么是微服务架构,.netCore微服务选型
什么是微服务架构,.netCore微服务选型 https://www.cnblogs.com/uglyman/p/9182485.html 开发工具:VS2017 .Net Core 2.1 什么是微 ...
- leecode-39. Combination Sum
1.问题描述: Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all ...