【双向队列,单向队列,坑爹的题目】Uva 210 Concurrency Simulator
来源:互联网 发布:网络摄影机app 编辑:程序博客网 时间:2024/06/01 18:50
Problem Description
我的天,这个题目无法理解,只能强行跟着别人博客的代码理解题目了。先输入t组测试样例,每组结果之间有空行。每组测试样例输入n,t1,t2,t3,t4,t5,Q,分别表示有n个程序,五种情况需要对应的时间,每次最多运行那么多时间。(赋值)(打印)(lock)(unlock)(end)lock, unlock这两个是重点。这两个lock,unlock出现没有什么影响,如果连续两个lock,就会将该程序,放到一个阻止队列的尾部,当在遇到unlock的时候,阻止队列前面出来,插入到等待队列的首部。直到阻止队列为空。阻止队列我们用正常的队列模拟,等待队列我们用两端队列模拟
代码:直接看代码理解把少年
#include <bits/stdc++.h>using namespace std;const int N = 1005;int flag = 0;deque<int> qr;//执行队列queue<int> qb;//等待队列vector<string> prg[N];//对应每个程序的代码string s;int t[N], p[N], var[26], lim;//运行第几个程序每一行对应的时间,对应的程序到了第几行,//对应的字母的赋值,每次最多可以运行多少时间。void run(int i){ int rt = lim, v; string cur; while(rt > 0) { cur = prg[i][p[i]]; if(cur[2] == '=') // 赋值 { rt -= t[0]; v = cur[4] - '0'; if(cur.size() == 6) v = v * 10 + cur[5] - '0'; var[cur[0] - 'a'] = v;// 相应的字母赋上对应的值 } else if(cur[2] == 'i') //print { rt -= t[1]; printf("%d: %d\n", i, var[cur[6] - 'a']); } else if(cur[2] == 'c') //lock { rt -= t[2]; if(flag)//连续两次出现lock,入队列 { qb.push(i); return; } else flag = 1; } else if(cur[2] == 'l') //unlock { flag = 0; rt -= t[3]; if(!qb.empty())//将队列的程序,从前插入 { v = qb.front(); qb.pop(); qr.push_front(v); } } else return; //end ++p[i];//对应第几个程序运行到第几行 } qr.push_back(i);}int main(){ int cas, n; scanf("%d", &cas);//cas组测试数据 while(cas--) { scanf("%d", &n); for(int i = 0; i < 5; ++i) scanf("%d", &t[i]); scanf("%d", &lim); for(int i = 1; i <= n; ++i)//n个程序 { prg[i].clear(); while(getline(cin, s))//对应着n个代码 { if(s == "") continue; prg[i].push_back(s); if(prg[i].back() == "end") break; } qr.push_back(i); } memset(p, 0, sizeof(p)); memset(var, 0, sizeof(var)); while(!qr.empty())//队首出列 { int cur = qr.front(); qr.pop_front(); run(cur); } if(cas) puts(""); } return 0;}
阅读全文
0 0
- 【双向队列,单向队列,坑爹的题目】Uva 210 Concurrency Simulator
- UVa 210 Concurrency Simulator(双端队列)
- UVA - 210 - Concurrency Simulator <双端队列>
- UVa 210 Concurrency Simulator(双端队列)
- UVa 210 Concurrency Simulator(双端队列)
- UVA210 concurrency simulator (双向队列 & 模拟)
- UVa 210 - Concurrency Simulator(模拟+双端队列)
- 【日常学习】【双端队列】 Uva - 210 Concurrency Simulator题解
- 队列数组存储Uva Concurrency Simulator
- 210 - Concurrency Simulator【模拟、双端队列】
- UVA - 210 Concurrency Simulator
- Uva - 210 - Concurrency Simulator
- UVa 210 Concurrency Simulator
- 【UVa】[210]Concurrency Simulator
- uva 210 Concurrency Simulator
- 双向队列和单向队列
- UVA 210(p139)----Concurrency Simulator
- Queue 队列分析(单向队列,双向队列,阻塞队列)
- 第 9 章 存储过程与函数
- 排列组合n个元素中选取m个元素
- js中‘0’到底是 true 还是 false
- OmniGraffle
- Nginx应用&Memcached配置&LNMP架构&Web压力测试&性能优化
- 【双向队列,单向队列,坑爹的题目】Uva 210 Concurrency Simulator
- redis保存对象
- 51nod 1130 N的阶乘的长度 V2(斯特林近似) 【数学】【斯特林公式】
- slider 滑动条 mouseup有时失效的原因
- MYSQL中数据约束
- 39-41.Struts2_短路验证&非字段验证&相同的验证规则使用同一条响应消息&自定义验证器
- Xilinx的ISim仿真随机数的生成
- C/C++ 结构体对齐原则
- 学习笔记: 源码 softmax_loss_layer.cpp 略析