UVA-804 模拟
来源:互联网 发布:应用数据可以删除吗 编辑:程序博客网 时间:2024/05/22 12:04
将每个translation的输入和输出place全部记录下来,模拟即可,当所有translation都不能工作时,就说明dead了。
AC代码:
#include<cstdio>#include<vector>using namespace std;const int maxn = 100 + 5;struct node{ vector<int> in, out;}tran[maxn];int p[maxn]; //the number of tokens in all placesint main(){ int pn, tn, nf, kase = 1; while(scanf("%d", &pn) == 1 && pn){ for(int i = 1; i <= pn; ++i){ scanf("%d", &p[i]); } scanf("%d", &tn); for(int i = 1; i <= tn; ++i){ int x; while(scanf("%d", &x) == 1 && x){ if(x < 0) tran[i].in.push_back(-x); else tran[i].out.push_back(x); } } scanf("%d",&nf); bool dead = 0; int h; for(h = 0; h < nf; ++h){ int cnt = 0; for(int i = 1; i <= tn; ++i){ bool flag = 1; vector<int> &in = tran[i].in, &out = tran[i].out; for(int j = 0; j < in.size(); ++j){ if(p[in[j]] == 0) { flag = 0; while(j) p[in[--j]]++; // break; } else p[in[j]]--; } if(!flag) ++cnt; else { for(int k = 0; k < out.size(); ++k) p[out[k]]++; break; } } if(cnt == tn) { dead = 1; break; } } if(dead) printf("Case %d: dead after %d transitions\n", kase++, h); else printf("Case %d: still live after %d transitions\n", kase++, nf); printf("Places with tokens:"); for(int i = 1; i <= pn ; ++i){ if(p[i]) printf(" %d (%d)", i, p[i]); } printf("\n\n"); for(int i = 1; i <= tn ; ++i) { tran[i].in.clear(); tran[i].out.clear(); } } return 0;}
如有不当之处欢迎指出!
0 0
- UVA-804 模拟
- uva 804 Petri Net 模拟
- UVa 804 - Petri Net Simulation(模拟)
- UVA 10196 模拟题。。
- UVa 100 简单模拟
- UVa 602 简单模拟
- Uva 11039(排序+模拟)
- UVA 11039 模拟
- UVa 10189 Minesweeper (模拟)
- uva 11995 STL模拟
- uva 10205 模拟
- UVA 514 - Rails(模拟)
- uva 502(模拟)
- uva--188+模拟
- UVA Palindromes(模拟)
- UVA Artificial Intelligence?(模拟)
- UVA 401-Palindromes(模拟)
- UVa 227 模拟
- 一只小蜜蜂...
- [BZOJ2055]80人环游世界(有源汇有上下界的费用流)
- Jackson框架介绍
- C语言 · 高精度乘法
- 汽水瓶——华为研发工程师编程题
- UVA-804 模拟
- 消息队列----RabbitMQ基础概念详细介绍
- 把keilC51中不使用的代码禁止分配空间,为程序瘦身!
- sql索引语法
- DOM事件探秘
- AIDL小结
- C语言scanf函数详细解释
- 记简单的输入框输入密码
- [041]一个简单的Makefile教程