习题6-7 Petri网模拟(Petri Net Simulation, ACM/ICPC World Finals 1998, UVa804)
来源:互联网 发布:免清洗 知乎 编辑:程序博客网 时间:2024/04/30 06:45
0. 只是一道简答的模拟,但是我还是有点障碍。。。菜啊。。多思考。。
1. 结构体中有map时,不能用memset来初始化。
1. 结构体中有map时,不能用memset来初始化。
#include <iostream>#include <string>#include <vector>#include <stack>#include <queue>#include <deque>#include <set>#include <map>#include <algorithm>#include <sstream>#include <utility>#include <cstring>#include <cstdio>#include <cstdlib>#include <ctime>#include <cmath>#include <cctype>#define CLEAR(a, b) memset(a, b, sizeof(a))#define IN() freopen("in.txt", "r", stdin)#define OUT() freopen("out.txt", "w", stdout)#define LL long long#define maxn 105#define maxm 200005#define mod 1000000007#define INF 1000000007#define eps 1e-5#define PI 3.1415926535898#define N 26using namespace std;//-------------------------CHC------------------------------//int NP, NT;int p[maxn];struct T {map<int, int> pre, next;}t[maxn];int main() {int kase = 1;while (scanf("%d", &NP) && NP) {for (int i = 1; i <= NP; ++i) scanf("%d", &p[i]);scanf("%d", &NT);for (int i = 1; i <= NT; ++i) t[i].next.clear(), t[i].pre.clear();int x;for (int i = 1; i <= NT; ++i) {while (scanf("%d", &x) && x) {if (x < 0) t[i].pre[-x]++;else t[i].next[x]++;}}int trans;scanf("%d", &trans);int cnt = 0;bool ok = true;while (ok) {ok = false;for (int i = 1; i <= NT; ++i) {bool can = true;for (auto j : t[i].pre)if (p[j.first] < j.second) can = false;if (!can) continue;for (auto j : t[i].pre)p[j.first] -= j.second;for (auto j : t[i].next)p[j.first] += j.second;cnt++, ok = true;if (cnt >= trans) { ok = false; break; }}}if (cnt >= trans) printf("Case %d: still live after %d transitions\n", kase++, trans);else printf("Case %d: dead after %d transitions\n", kase++, cnt);printf("Places with tokens:");for (int i = 1; i <= NP; ++i)if (p[i]) printf(" %d (%d)", i, p[i]);puts("\n");}return 0;}
阅读全文
0 0
- UVa804 习题 6-7 Petri网模拟(Petri Net Simulation,ACM/ICPC World Finals 1998)
- 习题6-7 Petri网模拟(Petri Net Simulation, ACM/ICPC World Finals 1998, UVa804)
- uva804 Petri Net Simulation [PKU2017SC](模拟)
- [刷题]算法竞赛入门经典(第2版) 6-7/UVa804 - Petri Net Simulation
- UVa 804 - Petri Net Simulation(模拟)
- 804 - Petri Net Simulation(简单魔模拟)
- 804 - Petri Net Simulation
- 804 - Petri Net Simulation
- Petri Net Simulation UVA
- UVa 804 Petri Net Simulation
- Uva - 804 - Petri Net Simulation
- UVA 804 Petri Net Simulation
- UVa806 习题6-8 空间结构(Spatial Structures,ACM/ICPC World Finals 1998)
- 习题6-8 空间结构(Spatial Structures, ACM/ICPC World Finals 1998, UVa806)
- [中等] UVa OJ 804 Petri Net Simulation
- 习题3-6 纵横字谜的答案(Crossword Answers, ACM/ICPC World Finals 1994, UVa232)
- 习题6-12 筛子难题(A Dicey Problem, ACM/ICPC World Finals 1999, UVa810)
- 习题6-13 电子表格计算器(Spreadsheet Calculator, ACM/ICPC World Finals 1992, UVa215)
- verilog二进制转BCD码(加三移位法)
- 编译程序时出现Lc.exe错误,代码为-1
- QTableWidget 点击标题栏 设置排序
- C++虚基类构造函数详解(调用顺序)之一
- MT 195 Queries查询
- 习题6-7 Petri网模拟(Petri Net Simulation, ACM/ICPC World Finals 1998, UVa804)
- Jetty的第一次接触(启动)
- Java自带的性能监测工具用法简介——jstack、jconsole、jinfo、jmap、jdb、jsta、jvisualvm
- 爬虫第一天(2)
- Spring Cloud Bus
- 汇编指令:rep stos
- 约瑟夫环Java实现
- 信息化时代,文件销毁志在必行
- android 拨打电话