UVA210 双端队列模拟并行程序
#include<iostream> #include<algorithm> #include<string> #include<sstream> #include<vector> #include<queue> #include<cstring> using namespace std; const int maxn = 10001; //uva210:题意 模拟n个程序的并行执行,有赋值,打印,lock,unlock,end五种。 //输入n,t1,t2,t3,t4,t5,Q; int n, t1, t2, t3, t4, t5, Q; deque<int>wait;//等待队列 deque<int>stop;//阻止队列 int num[maxn]; int main(void) { cin >> n >> t1 >> t2 >> t3 >> t4 >> t5 >> Q; string s; int id = 0; while(getline(cin,s)) { char c = s[2]; while (Q) { if (c == '='&&Q-t1>=0) { int ch = s[1]; num[ch-'a']==(int)s } } } return 0; } #include<iostream> #include<stack> #include<deque> #include<vector> int n, t1, t2, t3, t4, t5, Q; deque<int>wait;//阻塞队列 deque<int>ready;//等待队列 vector<string> str;//存储执行语句 int var[101];//存储变量 int block; void run(int i)//在ready队列中执行到第i个(str下标)的命令 { int time = Q; char c; while(time>0) { c = str[i][2]; if(c=='=') { time -= t1; //赋值范围为0-99 var[str[i][0] - 'a'] = isdigit(str[i][4]) ? (int)str[i][4] * 10 + str[i][5] : (int)str[i][5]; } else if(c=='i') { time -= t2; cout << i<<' ' << var[str[i][6]] << endl; } else if(c=='c') { if(!ready.empty()&&block) { wait.push_back(i); return; } time -= t3; block = 1; } else if(c=='l') { if(!wait.empty()) { ready.push_back(wait.front()); wait.pop_front(); } block = 0; time -= t4; } else { time -= t5; return; } } } int main() { //输入 cin >> n >> t1 >> t2 >> t3 >> t4 >> t5 >> Q; string s; for(int i=1;i<=n;i++) { while(getline(cin,s)) { str[i] = s; ready.push_front(i);//str的下标传入到ready中,之后处理 } } //处理 while (!ready.empty()) { int x = ready.front(); ready.pop_front(); // cout<<x<<" "; run(x); // 依次执行准备列队的队头 } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现