#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. java-String-StringBuffer

    一 String 1.1 == 和 equal() System.out.println("-------两个内容相同,创建方式不同的字符串,面试题--------"); Stri ...

  2. java-静态-单例-继承

    概要图 一.静态 1.1 静态方法 创建对象就是为了产生实例,并进行数据的封装. 而调用功能时,确没有用到这些对象中封装的数据. 该对象的创建有意义吗?虽然可以编译并运行,但是在堆内存中空间较为浪费. ...

  3. OpenLayers添加和删除控件

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. 《2019上半年DDoS攻击态势报告》发布:应用层攻击形势依然严峻,海量移动设备成新一代肉鸡

    2019年上半年,阿里云安全团队平均每天帮助用户防御2500余次DDoS攻击,与2018年持平.目前阿里云承载着中国40%网站流量,为全球上百万客户提供基础安全防御.可以说,阿里云上的DDoS攻防态势 ...

  5. JQuery--val()、html()、text()

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

  6. 一句python,一句R︱python中的字符串操作、中文乱码、NaN情况

    一句python,一句R︱python中的字符串操作.中文乱码.NaN情况 先学了R,最近刚刚上手Python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句pytho ...

  7. 【JZOJ4922】【NOIP2017提高组模拟12.17】环

    题目描述 小A有一个环,环上有n个正整数.他有特殊的能力,能将环切成k段,每段包含一个或者多个数字.对于一个切分方案,小A将以如下方式计算优美程度: 首先对于每一段,求出他们的数字和.然后对于每段的和 ...

  8. ansible Ansible Galaxy ansible-playbook 安装 使用 命令 笔记 生成密钥 管控机 被管控机 wget epel源

    笔记 ansible 安装 与salt对比 相同 都是为了同时在多台机器上执行相同的命令 都是python开发 不同 agent(saltstack需要安装.ansible不需要) 配置(salt配置 ...

  9. 基于matlab的傅里叶变换

    原文出处https://blog.csdn.net/qq_37366291/article/details/79832886 例子1 作用:使用傅里叶变换找出隐藏在噪声中的信号的频率成分.(指定信号的 ...

  10. 纯CSS3实现iOS7扁平化图标

    在线演示 本地下载