804-petri Net Simulation (Simple magic Simulation)

Source: Internet
Author: User

Relatively simple, attention to the problem is that an input library may charge multiple goods for conversion, the input needs to be special processing

Time Best Time
problem Verdict Lang Rank Submit
< Span style= "float:right; padding-right:5px "> |  discuss 804 - petri Net Simulation  accepted c++ 0.099 0.028 14 2 mins Ago
#include <cstdio> #include <vector> #include <algorithm>using namespace std;const int maxn = 105;int NP,    nt;struct node{int id;    int num; Node (int id = 0,int num = 0): ID (ID), num (num) {};}; Vector<node>in[maxn];vector<node>out[maxn];int Np_num[maxn],arr[100005];bool Solve () {for (int i = 1; I &lt ; = NT;        i++) {int ok = 1;            for (int j = 0; J < In[i].size (); j + +) {int id = In[i][j].id,num = in[i][j].num;                if (Np_num[id] < num) {OK = 0;            Break }} if (OK) {for (int j = 0; J < In[i].size (); j + +) {int id = In[i][j].id,num = i                N[i][j].num;            NP_NUM[ID]-= num;                } for (int j = 0; J < Out[i].size (); j + +) {int id = Out[i][j].id,num = out[i][j].num;            NP_NUM[ID] + = num;        } return true; }} return false;}    int main () {int case = 1; Freopen ("In.txt", "R", stdin);        while (scanf ("%d", &AMP;NP) && np) {for (int i = 1; I <= np; i++) scanf ("%d", &np_num[i]);        scanf ("%d", &nt);            for (int i = 1; I <= nt; i++) {int cnt = 0; In[i].clear ();            Out[i].clear ();            while (scanf ("%d", &arr[cnt]) && arr[cnt]) cnt + +;            Sort (Arr,arr + cnt);            if (cnt = = 0) continue;            int id = Arr[0],num = 1;                        for (int j = 1; j < CNT; J + +) {if (arr[j]! = Arr[j-1]) {if (ID < 0)                    In[i].push_back (Node (-id,num));                    if (Id > 0) out[i].push_back (Node (id,num));                    id = arr[j];                num = 1;            } else num++;            } if (ID < 0) in[i].push_back (Node (-id,num));        if (Id > 0) out[i].push_back (Node (id,num)); } int Cir,i;        scanf ("%d", &AMP;CIR);        for (i = 1; I <= Cir; i++) {if (!solve ()) break;        } if (i > Cir) printf ("Case%d:still Live after%d transitions\n", case++,i-1);        else printf ("Case%d:dead after%d transitions\n", case++,i-1);        printf ("Places with Tokens:");        for (int i = 1; I <= np; i++) {if (Np_num[i]) printf ("%d (%d)", i,np_num[i]);    } puts ("\ n"); } return 0;}


804-petri Net Simulation (Simple magic Simulation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.