首页 技术 正文
技术 2022年11月15日
0 收藏 852 点赞 3,241 浏览 1085 个字

将每个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;}

如有不当之处欢迎指出!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844