将每个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 places

int 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;
}

如有不当之处欢迎指出!

UVA-804 模拟的更多相关文章

  1. UVa 12100 (模拟) Printer Queue

    用一个队列模拟,还有一个数组cnt记录9个优先级的任务的数量,每次找到当前最大优先级的任务然后出队,并及时更新cnt数组. #include <iostream> #include < ...

  2. uva 10205 模拟

    模拟题 题目描述挺长的.... #include <cstdio> #include <cstdlib> #include <cmath> #include < ...

  3. UVa 101 (模拟) The Blocks Problem

    题意: 有n个木块及n个木块堆,初始状态是第i个木块在第i个木块堆上.对应有四种操作,然后输出最终状态. 分析: 用一个vector<int>模拟一个木块堆,进行相应操作即可. #incl ...

  4. Uva - 804 - Petri Net Simulation

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

  5. 【每日一题】Flooded! UVA - 815 模拟阅读格式题

    https://cn.vjudge.net/problem/UVA-815 题意:给你一个矩阵,每个格子的数代表一个海拔并且每个格子的面积100平方米.给你整个区域的降水量(立方米),问降水量(米). ...

  6. UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494

    白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...

  7. 【习题 6-7 UVA - 804】Petri Net Simulation

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟就好 [代码] /* 1.Shoud it use long long ? 2.Have you ever test sever ...

  8. 【紫书】 Unix ls UVA - 400 模拟

    题意:中文版https://vjudge.net/problem/UVA-400#author=Zsc1615925460 题解:首先读取字符,维护一个最长字符串长度M,再排序. 对于输出,写一个pr ...

  9. UVA - 11995 模拟

    #include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #i ...

  10. Paper Folding UVA - 177 模拟+思路+找规律

    题目:题目链接 思路:1到4是很容易写出来的,我们先考虑这四种情况的绘制顺序 1:ru 2:rulu 3:rululdlu 4:rululdluldrdldlu 不难发现,相较于前一行,每一次增加一倍 ...

随机推荐

  1. CSS深入理解学习笔记之vertical-align

    1.vertical-align基本认识 支持的属性值: ①线类:baseline(默认),top,middle,bottom ②文本类:text-top,text-bottom ③上标下标类:sub ...

  2. js实现最短时间走完不同速度的路程

    题目: 现在有一条公路,起点是0公里,终点是100公里.这条公路被划分为N段,每一段有不同的限速.现在他们从A公里处开始,到B公里处结束.请帮他们计算在不超过限速的情况下,最少需要多少时间完成这段路程 ...

  3. IO (三)

    1 转换流 1.1 InputStreamReader 1.1.1 InputStreamReader简介 InputStreamReader是字节流通向字符流的桥梁.它使用指定的charset读取字 ...

  4. grep使用技巧一:模式pattern为字符串文件

    pattern文件: antc  areq  bdos  bogt   …… igs.txt文件: abmf    298.4725   16.2623   abpo     47.2292  -19 ...

  5. Jenkins初识

    Jenkins Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能. 功能 Jenkins功能包括 ...

  6. chrome disable-web-security 关闭安全策略 解决跨域

    Chrome 跨域访问线上接口 时间:2016-04-21 作者:zhongxia 前后端分离之后,联调的时候就会出现问题,那就是Ajax跨域问题. 跨域问题的解决方案有很多种比如常规的 后端使用CR ...

  7. apr-util的安装

    下载软件 下载链接: http://pan.baidu.com/s/1o6sOwgM http://pan.baidu.com/s/1hqIdcA4 ########安装apr######### ta ...

  8. JasperReport报表开发(一)--原理介绍

    1. JasperReport介绍 JasperReport 是一个开源的Java报表引擎,它不像其他的报表工具,例如Crystal报表是基于Java的,没有自己的表达式语法.Jasper Repor ...

  9. 《Thinking in Java》学习笔记(三)

    1>Java中的常量 使用final和static来修饰的变量称为常量,常量用大写字母表示,字母间用下划线连接. Java中定义常量有以下几种方式: interface ConstantInte ...

  10. HDU [P1533]

    二分图带权最小匹配(朴素) 只要换几个不等号的方向就行,不需要变换权值的正负 #include <iostream> #include <cstdio> #include &l ...