• poj 1364 查分约束


    #include<stdio.h>
    #include<iostream>
    #include<stack>
    #include<string.h>
    using namespace std;
    #define inf  999999999
    #define N 300
    struct node {
    	int u,v,w,next;
    }bian[N*10];
    int yong,n,head[N];
    void addedge(int u,int v,int w) {
    	bian[yong].v=v;
    	bian[yong].w=w;
    	bian[yong].next=head[u];
    	head[u]=yong++;
    }
    int bellman() {
    	int dis[N],visit[N],count[N];  
    	int cur,i;
    	for(i=0;i<=n;i++) 
    		   addedge(n+1,i,0);
    	for(i=0;i<=n+1;i++)
    		   dis[i]=inf;
    	memset(visit,0,sizeof(visit));
    	memset(count,0,sizeof(count));
    	stack<int>q;
    	dis[n+1]=0;
    	q.push(n+1);
    	while(!q.empty()) {
               cur=q.top();
    		   q.pop();
    		   visit[cur]=0;
    		   for(i=head[cur];i!=-1;i=bian[i].next)
    			   if(dis[bian[i].v]>dis[cur]+bian[i].w) {
    				   dis[bian[i].v]=dis[cur]+bian[i].w;
    				   if(!visit[bian[i].v]) {
    					   visit[bian[i].v]=1;
    				   if(++count[bian[i].v]>n)
    					   return 0;
    					   q.push(bian[i].v);
    				   }
    			   }
    	}
    	return 1;
    	}
    int main() {
    	int i,j,k,m;
    	char s[30];
    	while(scanf("%d",&n),n) {
    		scanf("%d",&m);
    	  yong=0;
    	  memset(head,-1,sizeof(head));
    	  while(m--) {
    		  scanf("%d%d%s%d",&i,&j,s,&k);
    		  if(s[0]=='g')
    			  addedge(i+j,i-1,-k-1);
    		  if(s[0]=='l')
    			  addedge(i-1,i+j,k-1);
    	  }
    	   if(bellman())
    		   printf("lamentable kingdom
    ");
    	   else
    		   printf("successful conspiracy
    ");
    	   }
    	return 0;
    }
  • 相关阅读:
    django之项目建立
    云监控服务比较
    2014 中华架构师大会 回顾
    计算字符串相似度算法——Levenshtein
    Maximum Likelihood 最大似然估计
    Laplacian eigenmap 拉普拉斯特征映射
    SparseLDA算法
    eigenvalues problem
    kernel function
    半监督学习[转]
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410861.html
Copyright © 2020-2023  润新知