UVa 804 - Petri Net Simulation(模拟)
来源:互联网 发布:网络电视放不出来 编辑:程序博客网 时间:2024/04/28 03:52
模拟Petri网变迁,读懂题之后其实不难。
建一个petri结构体,ip、op是参与变迁的place的编号。用数组记录每个参与变迁的place的tokens改变量。剩下的就好办了,题目说明了只会有唯一解,所以只需要循环执行可以进行的变迁就好了。
#include<cstdio>#include<cstring>#include<vector>using namespace std;const int maxn=105;int p,t,np[maxn],lim;struct petri{ int ip,op,i[maxn],o[maxn],in[maxn],out[maxn];} pet[maxn];int main(){ int tt=0; while(scanf("%d",&p),p){ memset(pet,0,sizeof(pet)); for(int i=1;i<=p;++i) scanf("%d",&np[i]); scanf("%d",&t); for(int i=1;i<=t;++i){ int k; while(scanf("%d",&k),k){ if(k<0) ++pet[i].in[-k]; else ++pet[i].out[k]; } for(int j=1;j<=p;++j){ if(pet[i].in[j]) pet[i].i[++pet[i].ip]=j; if(pet[i].out[j]) pet[i].o[++pet[i].op]=j; } } scanf("%d",&lim); int cnt=0; for(int i=1;i<=t;++i){ bool flag=true; petri &k=pet[i]; for(int j=1;j<=k.ip;++j) if(np[k.i[j]]<k.in[k.i[j]]){flag=false;break;} if(!flag) continue; for(int j=1;j<=k.ip;++j) np[k.i[j]]-=k.in[k.i[j]]; for(int j=1;j<=k.op;++j) np[k.o[j]]+=k.out[k.o[j]]; i=0; if(++cnt>=lim) break; } if(cnt>=lim) printf("Case %d: still live after %d transitions\n",++tt,lim); else printf("Case %d: dead after %d transitions\n",++tt,cnt); printf("Places with tokens:"); for(int i=1;i<=p;++i) if(np[i]) printf(" %d (%d)",i,np[i]); printf("\n\n"); } return 0;}
0 0
- UVa 804 - Petri Net Simulation(模拟)
- UVa 804 Petri Net Simulation
- Uva - 804 - Petri Net Simulation
- UVA 804 Petri Net Simulation
- Petri Net Simulation UVA
- [中等] UVa OJ 804 Petri Net Simulation
- 804 - Petri Net Simulation(简单魔模拟)
- uva804 Petri Net Simulation [PKU2017SC](模拟)
- 804 - Petri Net Simulation
- 804 - Petri Net Simulation
- uva 804 Petri Net 模拟
- UVa804 习题 6-7 Petri网模拟(Petri Net Simulation,ACM/ICPC World Finals 1998)
- 习题6-7 Petri网模拟(Petri Net Simulation, ACM/ICPC World Finals 1998, UVa804)
- [刷题]算法竞赛入门经典(第2版) 6-7/UVa804 - Petri Net Simulation
- Petri Net
- petri net
- petri net
- 模拟:simulation,与 仿真:simulation
- [Leetcode] 59. Spiral Matrix II
- ddpush 学习之路 6 TCPClientBase.java
- [Leetcode] 60. Permutation Sequence
- 《JAVA与模式》之命令模式
- 证书文件编码格式介绍
- UVa 804 - Petri Net Simulation(模拟)
- [Leetcode] Single Number
- RTSP详解
- new和malloc
- LeetCode Longest Consecutive Sequence
- leetcode longest substring without repeating characters
- WPF设置图片显示不出来检查思路
- linux中/proc/*的简介
- 瑞典诗歌欣赏 Blott en dag