"Exercise 6-7 UVA-804" Petri Net Simulation

Source: Internet
Author: User

"Link" I am the link, point me:)
Test instructions


Enter the test instructions here

Exercises


Simulation is good.

Code

/*1.Shoud It use long long?2.Have ever test several sample (at least therr) yourself?3.Can You promise the solution are right? At Least,the main ideal4.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 namespaceStdConst intN = -;intN, M, Q;intRest[n +Ten];p Air<vector <int, Vector <int> > V[n +Ten];map <int,int> Cnt[n+10];intMain () {#ifdef Local_defineFreopen ("F:\\C++source\\Rush_in.txt ","R", stdin); Freopen ("F:\\C++source\\Rush_out.txt ","W", stdout);#endifIos::sync_with_stdio (0), Cin.tie (0);intKase =0; while(CIN >> n && N) { for(inti =1; I <= N;        i++) Cin >> Rest[i]; Cin >> m; for(inti =1; I <= m;            i++) {v[i].first.clear (), v[i].second.clear (); Cnt[i].clear ();intX 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 <<": ";BOOLAlive =true; Cin >> Q; for(inti =1; I <= Q; i++) {BOOLOK =false; for(intj =1; J <= M; J + +) {BOOLOk1 =true; for(intX:v[j].first) {if(Rest[x] < cnt[j][x]) Ok1 =false; }if(OK1) { for(intX:v[j].first) {rest[x]--; } for(intX: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(inti =1; I <= N; i++)if(Rest[i]) cout <<" "<< I <<" "<<"("<< Rest[i] <<")";    cout << Endl << Endl; }return 0;}

"Exercise 6-7 UVA-804" Petri Net 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.