【例题 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 ...
随机推荐
- select选择框实现跳转
select选择框实现跳转 零.启示 1.启示把bom里面的几个对象稍微有点印象,那么主干有了,学其它的就感觉添置加瓦,很简单 就是关注树木的主干 2.万能的百度,不过当然要你基础好学得多才能看得懂, ...
- kafka自带没web ui界面,怎么办?安装个第三方的
见 基于Web的Kafka管理器工具之Kafka-manager的编译部署详细安装 (支持kafka0.8.0.9和0.10以后版本)(图文详解)(默认端口或任意自定义端口)
- Impala与HBase整合
不多说,直接上干货! Impala可以通过Hive外部表方式和HBase进行整合,步骤如下: • 步骤1:创建hbase 表,向表中添加数据 create 'test_info', 'info' pu ...
- tcp为什么要三次握手
作者:大闲人柴毛毛链接:https://www.zhihu.com/question/24853633/answer/254224088来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...
- mount---挂载文件系统
挂载概念 Linux中的根目录以外的文件要想被访问,需要将其“关联”到根目录下的某个目录来实现,这种关联操作就是“挂载”,这个目录就是“挂载点”,解除次关联关系的过程称之为“卸载”. 注意:“挂载点” ...
- ActiveMQ学习总结(7)——ActiveMQ使用场景
MQ简介: MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过写和检索出入列队的针对应用程序的数据(消息)来通信,而无需专用连接来链接它们.消息传 ...
- TYVJ P1153 间谍网络
P1153 间谍网络 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 由于外国间谍的大量渗入,国家安全正处于高度危机之中.如果A间谍手中掌握着关于B间谍的犯罪 ...
- shape- 设置虚线
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...
- Qt之界面换肤
简述 常用的软件基本都有换肤功能,例如:QQ.360.迅雷等.换肤其实很简单,并没有想象中那么难,利用前面分享过的QSS系列文章,沃我们完全可以实现各种样式的定制! 简述 实现原理 效果 新建QSS文 ...
- js 关于网易淘宝移动端适配的学习
(function (doc, win) { // orientationchange:用户水平或者垂直翻转设备(即方向发生变化)时触发的事件;(屏幕大小发生变化) var docEl = doc.d ...