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(模拟)的更多相关文章

  1. PL/0编译器(java version) - Interpreter.java

    1: package compiler; 2:   3: import java.io.BufferedReader; 4: import java.io.BufferedWriter; 5: imp ...

  2. POJ 模拟题集合

    http://www.cppblog.com/Uriel/articles/101592.html 感觉这个暑假没有去年有激情啊,,,还没到状态就已经块上学了,,, 真是弱暴了,,,找几道模拟题刷刷. ...

  3. python之GIL官方文档 global interpreter lock 全局解释器锁

    0.目录 2. 术语 global interpreter lock 全局解释器锁3. C-API 还有更多没有仔细看4. 定期切换线程5. wiki.python6. python.doc FAQ ...

  4. python模拟面试技术题答案

      目录 Python4期模拟面试技术面试题答案............................................................................ ...

  5. Java 模拟面试题

    1.面向对象的特点 继承,封装,多态 2.对象和类的区别是什么? 对象是对客观事物的抽象,类是对对象的抽象.类是一种抽象的数据类型,它们的关系是,对象是类的实例,类是对象的模板. 3.静态成员和实例成 ...

  6. javascript设计模式 - 解释器模式(interpreter)

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Python Interpreter

    在开始之前,我们先限定下python解释器的意思.当讨论Python的时候,解释器这个词可以用在不同的地方.有的时候,解释器指的是Python Interpreter,也就是你在命令行交互界面上输入p ...

  8. 解释器模式Interpreter详解

    原文链接:https://www.cnblogs.com/java-my-life/archive/2012/06/19/2552617.html 在阎宏博士的<JAVA与模式>一书中开头 ...

  9. 如何实现模拟器(CHIP-8 interpreter) 绝佳杰作.

    转自 http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/ How to write an ...

随机推荐

  1. layui button按钮点击导致页面重新刷新的解决方案

    网友的解决方法:(我只想说,放屁!!!而且大家都在复制粘贴,浪费时间) 方法一:将button标签更换为input <input class="layui-btn test" ...

  2. MergeActors技巧

    打开界面 MergeActors的界面在Window>DeveloperTools>MergeActors 启用合并材质的方法 使用Use specific LOD Level 一种特殊情 ...

  3. jar 在windows 启动服务,卸载服务,停止端口

    参考:https://www.cnblogs.com/zhuchunlei/p/9469569.html 1,启动服务  install.bat @echo off SET JAVA_HOME=&qu ...

  4. C++入门经典-例6.14-通过指针连接两个字符数组

    1:字符数组是一个一维数组,引用字符数组的指针为字符指针,字符指针就是指向字符型内存空间的指针变量. char *p; char *string="www.mingri.book" ...

  5. Error:Connection activation failed: No suitable device found for this connection

    原文链接: https://blog.csdn.net/baiboya/article/details/80452822 ens33这个网卡一直无法激活,在网上找了半天,找到这个博主的文章,才解决,虽 ...

  6. DS博客作业8——课程总结

    1.当初你是如何做出选择计算机专业的决定的? 本来我在集美大学第一志愿专业是理学院的数据科学与大数据,奈何隔壁县城小伙伴比我高了2分,我就来到了网络,但经过我和她的交流,我意识到我们的课程差不多,同样 ...

  7. 191106DjangoORM之admin数据库管理组件

    一.admin数据库管理系统的使用 创建用户 >python manage.py createsuperuser 访问http://127.0.0.1/admin/ app/admin.py 注 ...

  8. 读取文件信息,并通过sscanf从中获取所需数据

    #include <stdio.h> #include <stdlib.h> #include <string.h> int file_length(char* f ...

  9. 如何在form组件中添加一个单选或者多选的字段

    解决办法: 需要在增加的类里面加入choices   具体操作如下:

  10. Ruby小白入门笔记之<Rubymine工具的快捷键>

    智能快捷 Ctrl+Alt+G:弹出Generate Ctrl+Alt+L:格式化代码 Alt+F1:切换视图(Project, Structure, etc.). Alt+F2:弹出预览窗口,可选择 ...