【习题 6-7 UVA - 804】Petri Net Simulation
生活随笔
收集整理的這篇文章主要介紹了
【习题 6-7 UVA - 804】Petri Net Simulation
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
【鏈接】 我是鏈接,點(diǎn)我呀:)
【題意】
在這里輸入題意
【題解】
模擬就好
【代碼】
/* 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_DEFINEfreopen("F:\\c++source\\rush_in.txt", "r", stdin);freopen("F:\\c++source\\rush_out.txt", "w", stdout);#endifios::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; }轉(zhuǎn)載于:https://www.cnblogs.com/AWCXV/p/7881450.html
總結(jié)
以上是生活随笔為你收集整理的【习题 6-7 UVA - 804】Petri Net Simulation的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Alt Gr or Shift
- 下一篇: python作业高级FTP(第八周)