LRJ-Example-06-01-Uva210
#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的更多相关文章
- Yii2 AR find用法 (2016-05-18 12:06:01)
Yii2 AR find用法 (2016-05-18 12:06:01) 转载▼ User::find()->all(); 返回所有数据 User::findOne($id); ...
- BlackArch Linux 2019.06.01 宣布发布
导读 BlackArch Linux是一个基于Arch Linux的发行版,专为渗透测试人员和安全研究人员设计,并包含大量渗透测试和安全实用程序,已宣布发布2019.06.01版本. BlackArc ...
- Cheatsheet: 2016 06.01 ~ 6.30
Other Swift for the Java guy: Part 1 – Getting Started Building a better code review process Creatin ...
- Cheatsheet: 2015 06.01 ~ 06.30
Web The Front-End Optimization Checklist [ASP.NET 5] Production Ready Web Server on Linux. Kestrel + ...
- 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 ...
- Cheatsheet: 2014 06.01 ~ 06.30
Mobile Developing iOS8 Apps Using Swift – Part 1- Hello World The Insider's Guide to Android Intervi ...
- Cheatsheet: 2013 06.01 ~ 06.22
.NET Git for Visual Studio and .NET developers How to download multiple files concurrently using Web ...
- Leetcode: 06/01
今天完成了三道题目,总结一下: 1: Length of last word(细节实现题) 此题有一些细节需要注意(比如 “a_ _” 最后一个单词是a, 而不是遇到空格就直接算成没有),别的基本就是 ...
- 常用Oracle分析函数详解 [http://www.cnblogs.com/benio/archive/2011/06/01/2066106.html]
学习步骤:1. 拥有Oracle EBS demo 环境 或者 PROD 环境2. copy以下代码进 PL/SQL3. 配合解释分析结果4. 如果网页有点乱请复制到TXT中查看 /*假设一个经理 ...
- Cheatsheet: 2017 06.01 ~ 06.30
.NET Porting a .NET Framework library to .NET Core Performance Improvements in .NET Core High-perfor ...
随机推荐
- new 在C++ 中的用法
我对C++一无所知 看参考手册 来看一下参考手册,总共有三种用法 下面是网站上给出的例子 // operator new example #include <iostream> // st ...
- Liferay 7:如何在Liferay Portlet中使用Angular, React, Vue.js等前端框架
https://web.liferay.com/zh/web/ivan.zaera/blog/-/blogs/modern-frontend-workflows-in-liferay-portal L ...
- 【CS Round #44 (Div. 2 only) A】Frequent Numbers
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 大水题 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #include &l ...
- Etag 和 If-None-Match
ETag是HTTP1.1中才加入的一个属性,用来帮助服务器控制Web端的缓存验证. 它的原理是这样的,当浏览器请求服务器的某项资源(A)时, 服务器根据A算出一个哈希值(3f ...
- 50道python面试题
1.大数据的文件读取 ① 利用生成器generator ②迭代器进行迭代遍历:for line in file 2.迭代器和生成器的区别 1)迭代器是一个更抽象的概念,任何对象,如果它的类有next方 ...
- OSGi Capabilities
OSGi bundle的Capability就是这个bundle所具有的能力. 就像淘宝上的每个店铺一样,它会说明自己都卖哪些东西,也就是Provide-Capability 我们这些剁手党就会根据自 ...
- Mysql+php报错原因
SQL syntax --语法错误,看near,错误会在near后引号中的内容 的附近 Table/Database....... dosen't existes ---表/库(库名/表名) 不存在 ...
- Directx11教程(48) depth/stencil buffer的作用
原文:Directx11教程(48) depth/stencil buffer的作用 在D3D11中,有depth/stencil buffer,它们和framebuffer相对应,如下图所 ...
- jmeter使用Badboy录制、检查点和参数化
jmeter使用Badboy录制 1.打开Badboy,在地址栏输入需要录制的网址,如:百度首页
- 【Django入坑之路】基础操作(过滤,继承,跳转)
1:自定过滤器 1创建templatetags文件夹 2在里面创建自定义py文件:固定格式: from django import template from django.utils.safestr ...