【习题 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 ...
随机推荐
- 把华为交换机设置成时钟源服务器(NTP)
把华为交换机设置成时钟源服务器(NTP),提供给下面客户端Linux服务器使用, 1,先设置交换机的时区,和正确时间 # 假设地理位置在中国北京,设置本地时区名称为BJ. 如果系统默认的UTC是伦敦时 ...
- 解决电信或网通的DNS劫持
大家有没有碰到访问一些不存在域名或者网站时,浏览器本应显示一个网址不存在之类的信息,但是因为现在很多ISP做了DNS劫持将不存在的域名或网址重定向到ISP的广告页面,烦人的狠.其实tomato可以解决 ...
- 【Django】视图系统
目录 FBV 与 CBV 给视图加装饰器 使用装饰器装饰CBV 关于dispatch()方法 Request对象 与 Response对象 request对象 response对象 @ *** 一个视 ...
- ldd---程序所需要的动态链接库
ldd本身不是一个程序,而仅是一个shell脚本:ldd可以列出一个程序所需要得动态链接库(so) [root@xiaolizi ~ ]$ ldd /usr/bin/ls linux-vdso.so. ...
- MySQL中好用的GROUP_CONCAT函数
今天看到同事的代码,又学到了一个有用的函数,刚看的时候不太懂,就搜了下用法,看下面这篇文章讲的挺详细就直接转载了,我也写不那么好,呵呵,感谢作者的无私奉献. http://blog.sina.com. ...
- C++虚表的原理,很好
下面这篇文章讲的很好. http://www.cnblogs.com/lihaosky/articles/1606502.html 假设我们有这样的一个类: class Base { public: ...
- dlmalloc 2.8.6 源代码具体解释(5)
本文章由vector03原创, 转载请注明出处. 邮箱地址: mmzsmm@163.com, 欢迎来信讨论. 3. 分配及实现 本章节介绍dlmalloc的分配算法和实现.由于存在多mspac ...
- android framework 02
Android底层开发1.安装Ubuntu系统2.Ubuntu配置开发环境: sudo apt-get install git-core gnupg flex bison gperf zip sudo ...
- mvc表单Form提交 --实体
1.方式1:字段加验证 @model MvcWeb.Models.UserInfo @{ ViewBag.Title = "Add"; } <h2>Add</h2 ...
- finally不管有没有错都会运行 finally 块用于清除 try 块中分配的任何资源,以及运行任何即使在发生异常时也必须执行的代码
finally 块用于清除 try 块中分配的任何资源,以及运行任何即使在发生异常时也必须执行的代码