#define _CRT_SECURE_NO_WARNINGS

 #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <istream>
#include <iostream>
#include <deque>
#include <queue> using namespace std; int t[]; // unit execution times, assignment, print, lock, unlock, end
int quantum; const int N = ; // up to 10 programs
vector<string> prog[N]; // programs
int pc[N]; // program counter for each program bool lock;
deque<int> qr;//ready queue of program ID
queue<int> qb;//blocked queue of program ID int var[]; // values of 26 shared variables void run(int i) // i -- program ID
{
int rt = quantum;
string stmt;
while (rt > )
{
stmt = prog[i][pc[i]];
if (stmt[] == '=') // assignment
{
rt -= t[];
// decimal number less than 100
int v = stmt[] - '';
if (stmt.size() == ) v = v * + stmt[] - '';
var[stmt[] - 'a'] = v;
}
else if (stmt[] == 'i') //print
{
rt -= t[];
printf("%d: %d\n", i, var[stmt[] - 'a']);
}
else if (stmt[] == 'c') //lock
{ if (lock)
{
// program counter is not incremented
// the first statement this program will execute when it runs will be the lock statement failed
qb.push(i);
return; // lose any of its quantum remaining
}
else
{
rt -= t[];
lock = true;
} }
else if (stmt[] == 'l') //unlock
{
rt -= t[];
lock = false;
if (!qb.empty())
{
qr.push_front(qb.front());
qb.pop();
}
}
else
return; //end ++pc[i]; // increment the program counter
}
qr.push_back(i);
} int main()
{
int T, n;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n); // number of programs for (int i = ; i < ; i++)
scanf("%d", &t[i]); scanf("%d", &quantum); for (int i = ; i <= n; i++)
{
prog[i].clear();
string s;
while (getline(cin, s))
{
if (s == "") continue; // empty line
prog[i].push_back(s);
if (s == "end") break;
}
qr.push_back(i);
} memset(pc, , sizeof(pc));
memset(var, , sizeof(var)); // all variables are initially set to zero while (!qr.empty())
{
int id = qr.front();
qr.pop_front();
run(id);
} if (T)
printf("\n");
}
return ;
}

LRJ-Example-06-01-Uva210的更多相关文章

  1. Yii2 AR find用法 (2016-05-18 12:06:01)

    Yii2 AR find用法 (2016-05-18 12:06:01) 转载▼     User::find()->all();    返回所有数据   User::findOne($id); ...

  2. BlackArch Linux 2019.06.01 宣布发布

    导读 BlackArch Linux是一个基于Arch Linux的发行版,专为渗透测试人员和安全研究人员设计,并包含大量渗透测试和安全实用程序,已宣布发布2019.06.01版本. BlackArc ...

  3. Cheatsheet: 2016 06.01 ~ 6.30

    Other Swift for the Java guy: Part 1 – Getting Started Building a better code review process Creatin ...

  4. Cheatsheet: 2015 06.01 ~ 06.30

    Web The Front-End Optimization Checklist [ASP.NET 5] Production Ready Web Server on Linux. Kestrel + ...

  5. JavaScript基础系列目录(2014.06.01~2014.06.08)

    下列文章,转载请亲注明链接出处,谢谢! 链接地址: http://www.cnblogs.com/ttcc/tag/JavaScript%20%E5%9F%BA%E7%A1%80%E7%9F%A5%E ...

  6. Cheatsheet: 2014 06.01 ~ 06.30

    Mobile Developing iOS8 Apps Using Swift – Part 1- Hello World The Insider's Guide to Android Intervi ...

  7. Cheatsheet: 2013 06.01 ~ 06.22

    .NET Git for Visual Studio and .NET developers How to download multiple files concurrently using Web ...

  8. Leetcode: 06/01

    今天完成了三道题目,总结一下: 1: Length of last word(细节实现题) 此题有一些细节需要注意(比如 “a_ _” 最后一个单词是a, 而不是遇到空格就直接算成没有),别的基本就是 ...

  9. 常用Oracle分析函数详解 [http://www.cnblogs.com/benio/archive/2011/06/01/2066106.html]

      学习步骤:1. 拥有Oracle EBS demo 环境 或者 PROD 环境2. copy以下代码进 PL/SQL3. 配合解释分析结果4. 如果网页有点乱请复制到TXT中查看 /*假设一个经理 ...

  10. Cheatsheet: 2017 06.01 ~ 06.30

    .NET Porting a .NET Framework library to .NET Core Performance Improvements in .NET Core High-perfor ...

随机推荐

  1. Leetcode55. Jump Game跳跃游戏

    给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: true ...

  2. ubuntu设置终端命令历史记录

    ----------------------------------------------- HISTTIMEFORMAT='%F %T ' # 使用HISTTIMEFORMAT在历史中显示TIME ...

  3. 2017年Android SDK下载安装及配置教程(附带原文地址)

    首先声明: Unity版本5.6.3f1 最近试着在Unity中利用高通做AR开发时,发布项目文件需要发布到Android平台,遇到一些问题,看了网上的一些资料,踩了一些坑,现在总结出来,希望有相同的 ...

  4. java 4对象群体的组织

    两个接口 collecion接口 元素构成的元素的群体 map接口 键值对组成的群体 Array类 Vector ArrayList 在数组上构建的类 Java集合框架介绍 集成过得数据结构 查询方法 ...

  5. day38 17-Spring的Bean的属性注入:注解方式

    这个类已经可以由Spring控制反转了,那么属性呢?属性分为普通属性和对象属性两部分. JSR是一个组织,和W3C一样是定义一些标准的.它里面也定义了一歌注解,Spring对这个注解也是支持的.其实这 ...

  6. $.inArray()方法

    $.inArray() 函数用于在数组中查找指定值,并返回它的索引值(如果没有找到,则返回-1) 提示:源数组不会受到影响,过滤结果只反映在返回的结果数组中. 语法 $.inArray( value, ...

  7. Hdu 1007 最近点对

    题目链接 Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. List.Sort 排序用法收集

    使用Lambda表达式,实现代码如下: private static void SortByLambda()        {            List<Article> list ...

  9. JS 寄生 继承

    寄生构造函数 寄生构造函数的用途目的:给String内置对象功能扩充 稳妥的构造函数 继承 对象冒充继承 一般继承 组合继承 原型链继承:借助于中转函数和已有对象 寄生式继承:把原型式+工厂式结合而来 ...

  10. laravel 极验(Geetest) 让验证更安全。

    整理的有些仓促,在9月15号之后会更新更加详细更加全面的文档,供给大家参考,学习! 1.简述 在网站开发中使用频率最高的工具之一便是验证码,验证码在此也是多种多样,不过简单的图片验证码已经可以被机器识 ...