【习题 6-7 UVA - 804】Petri Net Simulation
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
模拟就好
【代码】
/*
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_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的更多相关文章
- Uva - 804 - Petri Net Simulation
Input: petri.in A Petri net is a computational model used to illustrate concurrent activity. Each Pe ...
- [刷题]算法竞赛入门经典(第2版) 6-7/UVa804 - Petri Net Simulation
题意:模拟Petri网的执行.虽然没听说过Petri网,但是题目描述的很清晰. 代码:(Accepted,0.210s) //UVa804 - Petri Net Simulation //Accep ...
- UVA 10700 Camel trading 无括号的表达式 贪心
题意:给出只包含数字和+*的表达式,你可以自己安排每一个运算的顺序,让你找出表达式可能得到的最大值和最小值. 很明显,先乘后加是最小值,先加后乘能得到最大值. 其实不是很明显... 证明下: 数字的范 ...
- 动态规划 Dynamic Programming 学习笔记
文章以 CC-BY-SA 方式共享,此说明高于本站内其他说明. 本文尚未完工,但内容足够丰富,故提前发布. 内容包含大量 \(\LaTeX\) 公式,渲染可能需要一些时间,请耐心等待渲染(约 5s). ...
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- ACM训练计划建议(转)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- UVa第五章STL应用 习题((解题报告))具体!
例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...
- UVa 1600 Patrol Robot (习题 6-5)
传送门: https://uva.onlinejudge.org/external/16/1600.pdf 多状态广搜 网上题解: 给vis数组再加一维状态,表示当前还剩下的能够穿越的墙的次数,每次碰 ...
- UVa 536 Tree Recovery | GOJ 1077 Post-order (习题 6-3)
传送门1: https://uva.onlinejudge.org/external/5/536.pdf 传送门2: http://acm.gdufe.edu.cn/Problem/read/id/1 ...
随机推荐
- 【转】flex中的labelFunction(combox和dataGrid)
Flex中,对于显示一个字段,只需要指定对应字段属性给labelField即可,当需要上述所需要的功能的时候就得做个转换了,在Flex的基于List的组件都有一个labelFunction方法能很简单 ...
- 【玲珑杯 round#18 B】图论你先敲完模板
[Link]:http://www.ifrog.cc/acm/problem/1146 [Description] [Solution] 设f[i]表示在第i个点休息的话最少需要的体力值; f[i]= ...
- 洛谷 P1913 L国的战斗之伞兵
P1913 L国的战斗之伞兵 题目背景 L国即将与I国发动战争!! 题目描述 为了在敌国渗透作战,指挥官决定:派出伞兵前往敌国!然而敌国的风十分强烈,能让伞兵在同一高度不停转悠,直到被刮到一个无风区… ...
- [Python] Generates permutations
>>> import itertools >>> for p in itertools.permutations('ABCD'): ... print(p) ('A ...
- linux vim,vi编辑器的基础
在之前我也不知道为什么要学vim和vi编辑器,仅仅是听过别人说这个对与linux非常重要. 先说一下为什么要学习这个编辑器.个人的看书理解. 系统管理员的重要工作就是參与与设置某些重要软件的配置文件, ...
- UVA 558 Wormholes 【SPFA 判负环】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- jquery08
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- amaze ui表格斑马纹效果
amaze ui表格斑马纹效果 需要注意的是样式的写法,都是 am-table- ,很好记的 如果是条纹就是striped,如果是hover状态就是hover 用法很简单,点对应class,不同的cl ...
- Ubuntu 12.04使用演示
今年年初,发布了Ubuntu 12.04(代号Precise Pangolin),但正式版预计将于2012年的4月底发布,作者对最新版本的ubuntu做了试用,先将操作视频与大家分享.更多内容请关注本 ...
- C语言编程入门——程序练习(下)
C语言的一些简单操作练习. 互换两个数字: # include <stdio.h> int main(void) { int i = 3; int j = 5; int t; //将i ...