分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

【习题 6-7 UVA - 804】Petri Net Simulation

发布时间:2023-09-06 01:26责任编辑:傅花花关键词:暂无标签

【链接】 ?我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


模拟就好

【代码】

/*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 ideal4.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;}

【习题 6-7 UVA - 804】Petri Net Simulation

原文地址:http://www.cnblogs.com/AWCXV/p/7881450.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved