HDUST-1245 Interpreter(模拟)
1245: Problem E: Interpreter
时间限制: 1 Sec 内存限制: 128 MB
提交: 4 解决: 2
[提交][状态][讨论版]
题目描述
Problem E: Interpreter
A certain computer has 10 registers and 1000 words of RAM. Each register or RAM location holds a 3-digit integer between 0 and 999. Instructions are encoded as 3-digit integers and stored in RAM. The encodings are as follows:
- 100 means halt
- 2dn means set register d to n (between 0 and 9)
- 3dn means add n to register d
- 4dn means multiply register d by n
- 5ds means set register d to the value of register s
- 6ds means add the value of register s to register d
- 7ds means multiply register d by the value of register s
- 8da means set register d to the value in RAM whose address is in register a
- 9sa means set the value in RAM whose address is in register a to the value of register s
- 0ds means goto the location in register d unless register s contains 0
All registers initially contain 000. The initial content of the RAM is read from standard input. The first instruction to be executed is at RAM address 0. All results are reduced modulo 1000.
The input to your program consists of up to 1000 3-digit unsigned integers, representing the contents of consecutive RAM locations starting at 0. Unspecified RAM locations are initialized to 000.
The output from your program is a single integer: the number of instructions executed up to and including the halt instruction. You may assume that the program does halt.
输入
输出
样例输入
299
492
495
399
492
495
399
283
279
689
078
100
000
000
000
样例输出
16
#include<bits/stdc++.h> using namespace std;
const int N = + ;
const int M = + ;
#define mod %1000 int a[N], reg[M]; int Solve(int n){
auto cnt = ;
for(int i = ; ; i++){
++ cnt;
int t = a[i] / , x = (a[i] % ) / , y = a[i] % ;
a[i] = a[i] mod;
if(!t && reg[y]) i = reg[x] - ;
else if(t == ) return cnt;
else if(t == ) reg[x] = y;
else if(t == ) reg[x] = (reg[x] + y) mod;
else if(t == ) reg[x] = (reg[x] * y) mod;
else if(t == ) reg[x] = reg[y];
else if(t == ) reg[x] = (reg[x] + reg[y]) mod;
else if(t == ) reg[x] = (reg[x] * reg[y]) mod;
else if(t == ) reg[x] = a[reg[y]] mod;
else if(t == ) a[reg[y]] = reg[x] mod;
}
return -;
}
int main(){
char ch[];
int n = ;
while(fgets(ch, , stdin) != NULL){
sscanf(ch, "%d", &a[n ++]);
}
printf("%d\n", Solve( n ));
return ;
}
HDUST-1245 Interpreter(模拟)的更多相关文章
- PL/0编译器(java version) - Interpreter.java
1: package compiler; 2: 3: import java.io.BufferedReader; 4: import java.io.BufferedWriter; 5: imp ...
- POJ 模拟题集合
http://www.cppblog.com/Uriel/articles/101592.html 感觉这个暑假没有去年有激情啊,,,还没到状态就已经块上学了,,, 真是弱暴了,,,找几道模拟题刷刷. ...
- python之GIL官方文档 global interpreter lock 全局解释器锁
0.目录 2. 术语 global interpreter lock 全局解释器锁3. C-API 还有更多没有仔细看4. 定期切换线程5. wiki.python6. python.doc FAQ ...
- python模拟面试技术题答案
目录 Python4期模拟面试技术面试题答案............................................................................ ...
- Java 模拟面试题
1.面向对象的特点 继承,封装,多态 2.对象和类的区别是什么? 对象是对客观事物的抽象,类是对对象的抽象.类是一种抽象的数据类型,它们的关系是,对象是类的实例,类是对象的模板. 3.静态成员和实例成 ...
- javascript设计模式 - 解释器模式(interpreter)
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Python Interpreter
在开始之前,我们先限定下python解释器的意思.当讨论Python的时候,解释器这个词可以用在不同的地方.有的时候,解释器指的是Python Interpreter,也就是你在命令行交互界面上输入p ...
- 解释器模式Interpreter详解
原文链接:https://www.cnblogs.com/java-my-life/archive/2012/06/19/2552617.html 在阎宏博士的<JAVA与模式>一书中开头 ...
- 如何实现模拟器(CHIP-8 interpreter) 绝佳杰作.
转自 http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/ How to write an ...
随机推荐
- 【BZOJ4456】 [Zjoi2016]旅行者 / 【UOJ #184】 【ZJOI2016】旅行者
Description 小Y来到了一个新的城市旅行.她发现了这个城市的布局是网格状的,也就是有n条从东到西的道路和m条从南到北 的道路,这些道路两两相交形成n×m个路口 (i,j)(1≤i≤n,1≤j ...
- unittest详解(五) 引入装饰器@classmethod
我们知道setUp()和setDown()的作用是在每条测试用例执行前准备测试环境以及用例测试结束后恢复测试环境,如果我们执行的测试类下所有测试用例的环境准备和环境复原的操作都是一样的,那么我们就没必 ...
- 前端学习之三——jquery选择器
Jquery中的选择器分为几大类:基本过滤选择器,层次选择器,内容过滤选择器,可见性过滤选择器,属性过滤选择器,子元素过滤选择器,表单对象选择器和表单对象属相过滤选择器. 1.非基本过滤选择器,一般需 ...
- C++入门经典-例5.11-动态分配空间,堆与栈
1:在程序中定义一个变量,它的值会被放入内存中.如果没有申请动态分配,它的值将会被放在栈中.栈中的变量所属的内存大小是无法被改变的,它们的产生与消亡也与变量定义的位置和存储方式有关.堆是一种与栈相对应 ...
- Dubbo HelloWord 与 Spring Boot 整合
实现消费者项目代码调用提供者项目代码,使用 zookeeper 做为注册中心 interface 项目 pom.xml <?xml version="1.0" encodin ...
- 正则表达式中常用的模式修正符有i、g、m、s、x、e详解
正则表达式中常用的模式修正符有i.g.m.s.x.e等.它们之间可以组合搭配使用. 它们的作用如下: //修正符:i 不区分大小写的匹配; //如:"/abc/i"可以与abc或a ...
- 介绍一下 NDK?
1.NDK 是一系列工具的集合 NDK 提供了一系列的工具,帮助开发者快速开发 C(或 C++)的动态库,并能自动将 so 和 java 应用一起打包成 apk.NDK 集成了交叉编译器,并提供了相应 ...
- ControlTemplate in WPF —— RadioButton
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...
- ORACLE官方全托管驱动 Oracle.ManagedDataAccess 12.1.0.1.0
以前用Oracle的时候,必须得装他臃肿的客户端,网上虽然也有提供直连Oracle的驱动,但也是要收费的,最近Oracle终于开窍了,提供了官方的全托管驱动. 这次是随Oracle ODAC 12c ...
- linux判断httpd端口是否打开
判断端口是否打开 lsof -i:80 判断端口打开了几个 lsof -i:80 | wc -l