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 ...
随机推荐
- 5.zip隐写术
首先分析pcapng,来得到flag. 先亮出下载地址:http://ctf5.shiyanbar.com/misc/LOL/LOL.pcapng 由于这是.pcapng,需要下载 wireshark ...
- Ajax的调试错误信息的输出
error: function(xhr, status, error) { console.log(xhr); console.log(status); console.log(error); }
- http verbs--Method Definitions
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html part of Hypertext Transfer Protocol -- HTTP/1. ...
- UIButton和UINavigationItem设置图片和文字位置
1.UIButton设置文字位置 有些时候我们想让UIButton的title居左对齐,我们设置 btn.textLabel.textAlignment = UITextAlignmentLeft 是 ...
- CABasicAnimation动画及其keypath值和作用
//tarnsform放大缩小动画 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transf ...
- 根据xml文件自动生成xsd文件
根据xml生成xsd文档 1. 找到vs自带的xsd.exe工具所在的文件夹位置: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin 注意 ...
- 利用URL重写隐藏复杂的URL
第一步:模拟映射页面 我们想在一个页面上点击guid.html链接,跳转到比较复杂URL的guid_{492f3e0b-848e-11da-9550-00e08161165f}.html页面.即定义一 ...
- IT兄弟连 JavaWeb教程 AJAX定义以及解决的问题
Ajax是"Asynchronous JavaScript And XML"的缩写(即:异步的JavaScript和XML),是一种实现无页面刷新获取服务器数据的混合技术,Ajax ...
- 阿里云(centos)下svn 服务器搭建
安装说明 系统环境:阿里云centos安装方式:yum install subversion 检查已安装版本 #检查是否安装了低版本的SVN[root@localhost /]# rpm -qa su ...
- Spring.Net框架学习错误集锦1
最近IoC框架非常火热,所以就学习了非常流行的IOC框架之一spring.NET,遇到如下问题: Error creating context 'spring.root': Could not loa ...