UVA - 210 Concurrency Simulator(双端队列)
2018-02-04 18:53
441 查看
点击打开题目链接
用一个双端队列deque存等待队列,一个普通队列存阻止队列,然后进行各项操作的模拟
一开始用的结构体存每个程序,然后队列里面存的也是结构体,T了。然后改用vector存程序,队列存每个程序的标号。
代码:
用一个双端队列deque存等待队列,一个普通队列存阻止队列,然后进行各项操作的模拟
一开始用的结构体存每个程序,然后队列里面存的也是结构体,T了。然后改用vector存程序,队列存每个程序的标号。
代码:
#include<bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; queue<int> stop; deque<int> wait; vector<string>ve[maxn]; string str; int l[maxn],cnt[27], tim[5]; int T; int inv; int n, q; void init() { memset(cnt, 0, sizeof(cnt)); memset(l, 0, sizeof(l)); } void input() { scanf("%d %d %d %d %d %d %d", &n, &tim[0], &tim[1], &tim[2], &tim[3], &tim[4], &q); for(int i = 0; i < n; i++) { ve[i].clear(); while(getline(cin, str)) { if(str == "") continue; ve[i].push_back(str); if(str == "end") break; } wait.push_back(i); } } void solve(int i) { int cur = q, v; while(cur > 0) { str = ve[i][l[i]]; //赋值 if(str[2] == '=') { cur -= tim[0]; int t = str[4] - '0'; if(str.length() == 6) t = t * 10 + (str[5] - '0'); cnt[str[0] - 'a'] = t; } //打印 else if(str[2] == 'i') { cur -= tim[1]; printf("%d: %d\n", i+1, cnt[str[6]-'a']); } //lock else if(str[2] == 'c') { cur -= tim[2]; if(inv) { stop.push(i); return; } else inv = 1; } //unlock else if(str[2] == 'l') { inv = 0; cur -= tim[3]; if(!stop.empty()) { v = stop.front(); stop.pop(); wait.push_front(v); } } else return; l[i]++; } wait.push_back(i); } int main() { scanf("%d", &T); while(T--) { init(); input(); while(!wait.empty()) { int f = wait.front(); wait.pop_front(); solve(f); } if(T) cout << endl; } return 0; }
相关文章推荐
- 【日常学习】【双端队列】 Uva - 210 Concurrency Simulator题解
- UVa210_Concurrency Simulator_双端队列的使用
- UVA - 210 - Concurrency Simulator <双端队列>
- 例题6-1 并行程序模拟 UVa210 双端队列
- 【双端队列】例题6-1 UVa 210
- UVa 210 Concurrency Simulator(双端队列)
- UVa 210 - Concurrency Simulator(模拟+双端队列)
- UVa 210 Concurrency Simulator(双端队列)
- Uva210 Concurrency Simulator 【双端队列deque】【例题6-1】
- UVa210 双端队列deque
- 例题6-1 双端队列 uva210
- UVa 210 Concurrency Simulator(双端队列)
- 紫书例题6-1 UVa210 ( 双端队列
- UVA 246 10-20-30 10-20-30游戏 模拟+STL双端队列deque
- 【双向队列,单向队列,坑爹的题目】Uva 210 Concurrency Simulator
- UVA - 442 Matrix Chain Multiplication 双端队列
- 210 - Concurrency Simulator【模拟、双端队列】
- UVA 11988 STL deque (双端队列||链表模拟)
- uva 11988 - Broken Keyboard (a.k.a. Beiju Text)(双端队列deque)
- UVA12100 Printer Queue 【双端队列】