【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

模拟就好

【代码】

/*
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的更多相关文章

  1. Uva - 804 - Petri Net Simulation

    Input: petri.in A Petri net is a computational model used to illustrate concurrent activity. Each Pe ...

  2. [刷题]算法竞赛入门经典(第2版) 6-7/UVa804 - Petri Net Simulation

    题意:模拟Petri网的执行.虽然没听说过Petri网,但是题目描述的很清晰. 代码:(Accepted,0.210s) //UVa804 - Petri Net Simulation //Accep ...

  3. UVA 10700 Camel trading 无括号的表达式 贪心

    题意:给出只包含数字和+*的表达式,你可以自己安排每一个运算的顺序,让你找出表达式可能得到的最大值和最小值. 很明显,先乘后加是最小值,先加后乘能得到最大值. 其实不是很明显... 证明下: 数字的范 ...

  4. 动态规划 Dynamic Programming 学习笔记

    文章以 CC-BY-SA 方式共享,此说明高于本站内其他说明. 本文尚未完工,但内容足够丰富,故提前发布. 内容包含大量 \(\LaTeX\) 公式,渲染可能需要一些时间,请耐心等待渲染(约 5s). ...

  5. ACM训练计划建议(写给本校acmer,欢迎围观和指正)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  6. ACM训练计划建议(转)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  7. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

  8. UVa 1600 Patrol Robot (习题 6-5)

    传送门: https://uva.onlinejudge.org/external/16/1600.pdf 多状态广搜 网上题解: 给vis数组再加一维状态,表示当前还剩下的能够穿越的墙的次数,每次碰 ...

  9. 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 ...

随机推荐

  1. OpenSUSE42.3 leap 开启ssh登陆

    一.产看ssh是否安装 OpenSUSE:~ # rpm -qa | grep ssh libssh2-1-1.4.3-18.3.x86_64openssh-askpass-1.2.4.1-12.1. ...

  2. Firefox 浏览器添加Linux jre插件

    在安装 Java 平台时,Java 插件文件将作为该安装的一部分包含在内.要在 Firefox 中使用 Java,您需要从该发行版中的插件文件手动创建符号链接指向 Firefox 预期的其中一个位置. ...

  3. noip 2018 day1 T2 货币系统 完全背包

    Code: #include<cstdio> #include<string> #include<cstring> #include<algorithm> ...

  4. ES6学习笔记(三)字符串的扩展

    ES6 加强了对 Unicode 的支持,并且扩展了字符串对象. 1.字符的Unicode表示法 JavaScript 允许采用\uxxxx形式表示一个字符,其中xxxx表示字符的 Unicode 码 ...

  5. scrollWidth到底是什么???

    贴上MDN对scrollwidth的定义: The Element.scrollWidth read-only property is a measurement of the width of an ...

  6. tar---打包,解压缩linux的文件和目录

    tar命令可以为linux的文件和目录创建档案.利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件.tar最初被用来在磁带上创建档案,现在,用户可以在 ...

  7. codeforces 543 C Remembering Strings

    题意:若一个字符串集合里的每一个字符串都至少有一个字符满足在i位上,仅仅有它有,那么这个就是合法的,给出全部串的每一个字符修改的花费,求变成合法的最小代价. 做法:dp[i][j].前i个串的状态为j ...

  8. Java的线程机制

    一.Java中实现多线程的两种方式1) 继承Thread类 Thread类包括了包括和创建线程所需的一切东西. Thread 最重要的方法是 run().编写线程程序时须要覆盖 run() 方法,ru ...

  9. Android照片墙完整版,完美结合 内存方案 LruCache 和 硬盘方案 DiskLruCache

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/34093441 在上一篇文章当中,我们学习了DiskLruCache的概念和基本用法 ...

  10. android 获取蓝牙已连接设备

    蓝牙如果手动配对并已连接,获取连接的设备: 1.检测连接状态: int a2dp = bluetoothAdapter.getProfileConnectionState(BluetoothProfi ...