#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. oracle-视图-索引-序列

    Oracle提高查询性能 一 视图 视图是一个虚拟表,就是对select查询的结果取个名字.其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值 ...

  2. LINUX普通猫的拔号工具介绍

    普通猫分为串口和PCI的,请查看 <关于网络设备概述 > 普通猫的拔号工具主要有kppp和wvdial:在Redhat/Fedora中,用system-config-network 或re ...

  3. 一款你不容错过的Laravel后台管理扩展包 —— Voyager – Laravel学院

    1.简介 Voyager是一个你不容错过的Laravel后台管理扩展包,提供了CRUD操作.媒体管理.菜单构建.数据管理等操作. 官网:https://the-control-group.github ...

  4. gcd(辗转相除法)

    证明过程: 假设用f(x, y)表示x,y的最大公约数,取k = x/y,b = x%y,则x = ky + b,如果一个数能够同时整除x和y,则必能同时整除b和y:而能够同时整除b和y的数也必能同时 ...

  5. PHP 学习1.3

    1.展示类的继承和静态的方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...

  6. activity与fragment之间的传递数据

    首先activity之间的数据传递就是 用intent和intent+bundle intent 传递 Intent i= new Intent(MainActivity.this,TheAty.cl ...

  7. poj 2001 Shortest Prefixes(字典树trie 动态分配内存)

    Shortest Prefixes Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15610   Accepted: 673 ...

  8. KMLLayer

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. vue中is的作用和用法

    回顾vue官方文档的过程中发现了is这个特性,虽然以我的写代码风格实在用不上,不过还是记录一下这个知识点 is的作用 <ul> <li></li> <li&g ...

  10. text-align:justify在项目中碰到的问题

    最近在项目中,使用了一个新的样式属性:text-align:justigy,这个属性在使用过程中遇到了一些小异常,现在总结下.  text-align有一个属性值为justify,为对齐之意.其实现的 ...