【例题 6-1 UVA - 210】Concurrency Simulator
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
队列模拟题。
注意初始化。。
然后题目中是让读入一个数据组数然后再输入数据的。
但样例。。但样例没有!?
【代码】
#include <bits/stdc++.h>
using namespace std;
const int P = 5;
const int N = 10;
const int L = 25;
int n,t[P+5],Q;
string Pro[N + 10][L + 10];
int lines[N + 10],cur[N+10];
deque <int> dl;
queue <int> blocked;
bool flag = 0,ru;
int val[300];
void run(int idx)
{
int QAQ = 0;
while (QAQ < Q)
{
cur[idx]++;
switch (Pro[idx][cur[idx]][2])
{
case '=':
{
QAQ += t[1];
int x;
if (isdigit(Pro[idx][cur[idx]][5]))
x = (Pro[idx][cur[idx]][4] - '0') * 10 + (Pro[idx][cur[idx]][5] - '0');
else
x = Pro[idx][cur[idx]][4] - '0';
val[Pro[idx][cur[idx]][0]] = x;
break;
}
case 'i'://print
{
QAQ += t[2];
cout << idx << ": "<<val[Pro[idx][cur[idx]][6]] << endl;
break;
}
case 'c'://lock
{
QAQ += t[3];
if (!flag)
flag = 1;
else
{
ru = true;
blocked.push(idx);
cur[idx]--;
return;
}
break;
}
case 'l'://unlock
{
QAQ += t[4];
flag = 0;
if (!blocked.empty())
{
dl.push_front(blocked.front());
blocked.pop();
}
break;
}
case 'd':
{
QAQ += t[5];
return;
break;
}
default:break;
}
}
}
int main()
{
/*freopen("F:\\rush.txt", "r", stdin);
freopen("F:\\rush_out.txt", "w", stdout);*/
int kase = 0;
int T;
scanf("%d", &T);
while (T--)
{
memset(val, 0, sizeof val);
if (kase > 0) puts("");
kase++;
scanf("%d", &n);
for (int i = 1; i <= 5; i++) scanf("%d", &t[i]);
scanf("%d", &Q);
getchar();
for(int i=1;i<=10;i++) lines[i]=0;
for(int i=1;i<=10;i++) cur[i]=0;
for (int i = 1; i <= n; i++)
{
string s;
while (getline(cin, s))
{
lines[i]++;
Pro[i][lines[i]] = s;
if (s =="end") break;
}
}
while (!dl.empty()) dl.pop_back();
while (!blocked.empty()) blocked.pop();
flag = false;
for (int i = 1; i <= n; i++) dl.push_back(i);
while (!dl.empty())
{
ru = false;
int x = dl.front();
dl.pop_front();
run(x);
if (!ru && lines[x] > cur[x]) dl.push_back(x);
}
}
return 0;
}
【例题 6-1 UVA - 210】Concurrency Simulator的更多相关文章
- uva 210 - Concurrency Simulator (并行程序模拟)
from CSDN: https://blog.csdn.net/su_cicada/article/details/87898579 例题6-1 并行程序模拟( Concurrency Simula ...
- Uva - 210 - Concurrency Simulator
自己写个双端队列,或者直接用deque,这个也比较好用 AC代码: #include <iostream> #include <cstdio> #include <cst ...
- UVa 210 Concurrency Simulator (双端队列+模拟)
题意:给定n个程序,每种程序有五种操作,分别为 var = constant(赋值),print var (打印), lock, unlock,end. 变量用小写字母表示,初始化为0,为程序所公有( ...
- 210 - Concurrency Simulator(WF1991, deque, 模拟)
题目有点长,理解题花了不少时间 粘下别人的翻译~ 你的任务是模拟n个程序(按输入顺序编号为1~n)的并行执行.每个程序包含不超过25条语句,格式一共有5种: var=constant(赋值): pri ...
- UVA 11423 - Cache Simulator (树状数组)
UVA 11423 - Cache Simulator (树状数组) option=com_onlinejudge&Itemid=8&category=523&page=sho ...
- UVa210 Concurrency Simulator (ACM/ICPC World Finals 1991) 双端队列
Programs executed concurrently on a uniprocessor system appear to be executed at the same time, but ...
- 并行程序模拟(Concurrency Simulator, ACM/ICPC World Finals 1991,Uva210)
任务介绍 你的任务是模拟n个程序的并行运算.(按照输入编号为1~n)的并行执行. 代码实现 #define LOCAL #include<bits/stdc++.h> using name ...
- UVa 210 并行程序模拟(deque)
题意: 模拟n个程序运行 格式一共有5种:var = constant(赋值):print var(打印):lock:unlock:end, 上述5种语句分别需要t1.t2.t3.t4.t5单位时间 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- Spark MLlib聚类KMeans
算法说明 聚类(Cluster analysis)有时也被翻译为簇类,其核心任务是:将一组目标object划分为若干个簇,每个簇之间的object尽可能相似,簇与簇之间的object尽可能相异.聚类算 ...
- OpenCV —— 图像局部与分割(二)
分水岭算法 将图像中的边缘转化成“山脉”,将均匀区域转化为“山谷” 分水岭算法首先计算灰度图像的梯度,这对山谷或没有纹理的盆地(亮度值低的点)的形成有效,也对山头或图像中没有主导线段的山脉(山脊对应的 ...
- Ubuntu 下安装 Python 虚拟环境
写在前面: 安装指南是在 Ubuntu 下面操作的.不同的 Linux 版本,安装指令不同.所以,该指南的某些指令对于像 CentOS 等非 Ubuntu 系统不适用. 为什么需要使用虚拟环境? 虚拟 ...
- 【2017 Multi-University Training Contest - Team 5】Rikka with Graph
[Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6090 [Description] 给你n个点; 让你在这n个点上最多连m条无向边; 使得 ∑ni= ...
- 【MongoDB】mongodump and mongorestore of mogodb
The another tool will be mentioned in this blog, namely mongodump and mongorestore. General speaking ...
- worktools-mmx 添加编译模块
1,添加模块到mmx.py文件 1>vim /home/zhangshuli/git/vanzo_team/xulei/mmx.py 2>按照格式"Gallery2": ...
- 20.Node.js EventEmitter的方法和事件
转自:http://www.runoob.com/nodejs/nodejs-tutorial.html EventEmitter 提供了多个属性,如 on 和 emit.on 函数用于绑定事件函数, ...
- 1.3 Quick Start中 Step 4: Send some messages官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Step 4: Send some messages Step : 发送消息 Kaf ...
- Maven学习笔记5
Web项目的部署: web部署 配置步骤 生成项目方式不是quickstart,而是webapp. 默认目录结构,需要修改配置. 重新配置project facets和java compiler.并重 ...
- php 生成文件txt到指定目录
// 向文件追加写入内容 $site = PHP_EOL.date("Y-m-d H:i:s")."world"; //PHP_EOL换行 // 使用 FILE ...