MZOJ # 56 King

analysis

Differential constraints board problem, with the prefix and the construction side, the road is like the longest run again

Note Initialization

Code

  1 /**********************
  2 User:Mandy.H.Y
  3 Langauge:c++
  4 Problem:
  5 Algorithm:
  6 **********************/
  7 
  8 #include<bits/stdc++.h>
  9 
 10 using namespace std;
 11 
 12 const int maxn = 105;
 13 const int maxm = 105;
 14 const int mod = 200;
 15 
 16 int n,m,first[maxn],size;
 17 int q[maxn << 1],l,r,cnt[maxn];
 18 bool vis[maxn];
 19 int dis[maxn];
 20 
 21 struct Edge{
 22     int v,w,nt;
 23 }edge[maxm << 1];
 24 
 25 template<class T>inline void read(T&x){
 26     x = 0;bool flag = 0;char ch = getchar();
 27     while(!isdigit(ch)) flag |= ch == '-',ch = getchar();
 28     while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
 29     if(flag) x = -x;
 30 }
 31 
 32 template<class T>void putch(const T x){
 33     if(x > 9) putch(x / 10);
 34     putchar(x % 10 | 48);
 35 }
 36 
 37 template<class T>void put(const T x){
 38     if(x < 0) putchar('-'),putch(-x);
 39     else putch(x);
 40 }
 41 
 42 void eadd(int u,int v,int w){
 43     edge[++size].v = v;
 44     edge[size].w = w;
 45     edge[size].nt = first[u];
 46     first[u] = size;
 47 }
 48 
 49 void readdata(){
 50     for(int i = 1;i <= m; ++ i){
 51         int s,nn,k;
 52         char c[5];
 53         read(s);read(nn);
 54         nn = s + nn;--s;
 55         scanf("%s",c);
 56         read(k);
 57         if(c[0] == 'g'){
 58             eadd(s,nn,k+1);
 59         }else {
 60             eadd(nn,s,-k+1);
 61         }
 62     }
 63 }
 64 
 65 void init(){
 66     size = 0;//注意初始化-- 
 67     memset(vis,0,sizeof(vis));
 68     memset(cnt,0,sizeof(cnt));
 69     memset(dis,0,sizeof(dis));
 70     memset(first,0, The sizeof (First));
 71 is      Memset (Edge, 0 , the sizeof (Edge));
 72  }
 73 is  
74  void Work () {
 75      the init ();
 76      ReadData ();
 77      L = R & lt = 0 ; // Note here initialization
 78      // because there is no following MOD 
79      
80      for ( int I = 0 ; I <= n-; ++ I) {
 81          Q [R & lt ++] = I;
 82          VIS [I] = . 1 ;
 83      }
 84     
 85     while(l != r){
 86         int u = q[l];
 87         l++;
 88         l %= mod;
 89         vis[u] = 0;
 90         if(cnt[u] > n) {
 91             puts("successful conspiracy");
 92             return;
 93         }
 94         int rr = (r-1+mod)%mod;
 95         if(l != r) if(dis[q[l]] < dis[q[rr]]) swap(q[l],q[rr]);
 96         for(int i = first[u];i;i = edge[i].nt){
 97             int v = edge[i].v;
 98             int w = edge[i].w;
 99             if(dis[v] < dis[u] + w){
100                 dis[v] = dis[u] + w;
101                 cnt[v] = cnt[u] + 1;
102                 if(!vis[v]){
103                     vis[v] = 1;
104                     q[r++] = v;
105                     r %= mod;
106                     int rr = (r-1+mod)%mod;
107                     if(l != r) if(dis[q[l]] < dis[q[rr]]) swap(q[l],q[rr]);
108                 }
109             }
110         }
111     }
112     puts("lamentable kingdom");
113 }
114 
115 int main(){
116 //    freopen("1.txt","r",stdin);
117     while(scanf("%d",&n)!=EOF && n){
118         read(m);
119         work();
120     }
121     return 0;
122 }
View Code

 

Guess you like

Origin www.cnblogs.com/Mandy-H-Y/p/11469077.html
#56