【习题 6-7 UVA - 804】Petri Net Simulation
Net 习题 UVa
2023-09-14 09:03:45 时间
【链接】 我是链接,点我呀:)
【题意】
【题解】
模拟就好【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int n, m, Q;
int rest[N + 10];
pair<vector <int>, vector <int> > v[N + 10];
map <int, int> cnt[N+10];
int main() {
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
freopen("F:\\c++source\\rush_out.txt", "w", stdout);
#endif
ios::sync_with_stdio(0), cin.tie(0);
int Kase = 0;
while (cin >> n && n) {
for (int i = 1; i <= n; i++) cin >> rest[i];
cin >> m;
for (int i = 1; i <= m; i++) {
v[i].first.clear(), v[i].second.clear();
cnt[i].clear();
int x;
cin >> x;
while (x != 0) {
if (x < 0) {
cnt[i][-x]++;
v[i].first.push_back(-x);
}
else {
v[i].second.push_back(x);
}
cin >> x;
}
}
cout << "Case " << ++Kase << ": ";
bool alive = true;
cin >> Q;
for (int i = 1; i <= Q; i++) {
bool ok = false;
for (int j = 1; j <= m; j++) {
bool ok1 = true;
for (int x : v[j].first) {
if (rest[x] < cnt[j][x]) ok1 = false;
}
if (ok1) {
for (int x : v[j].first) {
rest[x]--;
}
for (int x : v[j].second) {
rest[x]++;
}
ok = true;
break;
}
}
if (!ok) {
alive = ok;
cout << "dead after " << i-1 << " transitions" << endl;
break;
}
}
if (alive) {
cout << "still live after " << Q << " transitions" << endl;
}
cout << "Places with tokens:";
for (int i = 1; i <= n; i++)
if (rest[i])
cout << " " << i << " " << "(" << rest[i] << ")";
cout << endl << endl;
}
return 0;
}
相关文章
- 大数据的应用实例_net开源开发web框架
- .net 温故知新:【8】.NET 中的配置从xml转向json
- 浅谈.Net异步编程的前世今生----TPL篇
- C#/.NET值类型
- 数据库使用.NET连接MySQL数据库(net连接mysql)
- .net搭建ASP.NET应用程序在Linux系统上(linux搭建asp)
- .net安装 Linux 上的 ASP.NET 环境(linux安装asp)
- .net操作redis:构建高效数据处理平台(.net连接redis)
- Redis从入门到精通:.NET实现指南(redis.net书籍)
- 原理揭秘.NET 运用Redis图灵缓存原理(.net缓存redis)
- ASP.NET WebForm也可以这样用Ajax(程序猿,你知道不)
- Net访问Oracle数据库的简易方法(.net访问oracle)
- NET环境下 MySQL数据库应用实践(.net配合 mysql)
- Net框架如何使用MySQL数据库(.net能用mysql吗)
- Net和MySQL互相受益的强大组合(.net 与mysql)
- 型使用NET与MySQL开发动态类型Web应用程序(.net mysql 类)
- Asp.net中的mail的发送
- 关于.net(C#)中的跨进程访问的问题
- asp.net每天定点执行任务
- asp.net对中文汉字的加密与解密代码
- asp.net身份验证(最简单篇)
- ASP.NET中基于JQUERY的高性能的TreeView补充
- 把某个asp.net控件替换成自定义控件的方法