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 ...
随机推荐
- js点击复制文本
// 动态创建 input 元素 var aux = document.createElement("input"); // 获得需要复制的内容 aux.setAttribute( ...
- free内存监控
语 法: free [-bkmotV][-s <间隔秒数>] 补充说明:free指令会显示内存的使用情况,包括实体内存,虚拟的交换文件内存,共享内存区段,以及系统核心使用的缓冲区等. 参 ...
- HDU 4280 Island Transport(dinic+当前弧优化)
Island Transport Description In the vast waters far far away, there are many islands. People are liv ...
- Leetcode8.String to Integer (atoi)字符串转整数(atoi)
实现 atoi,将字符串转为整数. 该函数首先根据需要丢弃任意多的空格字符,直到找到第一个非空格字符为止.如果第一个非空字符是正号或负号,选取该符号,并将其与后面尽可能多的连续的数字组合起来,这部分字 ...
- Git push 出错 [The remote end hung up unexpectedly] - 简书
one day,my teamate using git push and occured this error. $ git push Counting objects: 2332669, done ...
- Lavavel 程序报错 MassAssignmentException in Model.php line 452: _token
Lavarel 用类似于下面命令插入数据时候出错 Comment::create($request->all()) 错误页面截图如下: 错误原因:下面这行代码应该写到对应的Model里面,而不是 ...
- web前端学习(四)JavaScript学习笔记部分(4)-- JavaScriptDOM对象
1.Javascript-DOM简介 1.1.HTML DOM 1.2.DOM操作HTML 1.2.1.JavaScript能够改变页面中的所有HTML元素 1.2.2.JavaScript能够改变页 ...
- 从零开始写一个npm包,一键生成react组件(偷懒==提高效率)
前言 最近写项目开发新模块的时候,每次写新模块的时候需要创建一个组件的时候(包含组件css,index.js,组件js),就只能会拷贝其他组件修改名称 ,但是写了1-2个后发现效率太低了,而且极容易出 ...
- Leetcode707.Design Linked List设计链表
设计链表的实现.您可以选择使用单链表或双链表.单链表中的节点应该具有两个属性:val 和 next.val 是当前节点的值,next 是指向下一个节点的指针/引用.如果要使用双向链表,则还需要一个属性 ...
- Directx11教程(51) 简单的billboard
原文:Directx11教程(51) 简单的billboard billboard称作公告板,通常用一个quad(四边形)表示[有的billboard用两个正交的quad表示],它的特点 ...