標籤:使用 os for io amp table
這是我見過最扯淡的題面之一。
題讀了差不多一半我都覺得我這題肯定讀不懂了,到最後終於看到重點了靠!
就是個差分約束大水題!毫無新意!
扯些什麼皇后想生孩子!生了男孩是個弱智!父王很擔心!這些有的沒的有意思嗎!!
題目就是給一個序列,告訴你 a b gt/lt c 表示從a起的b+1個數之和大於/小於c
就根據這個列不等式,要把> 或 <關係換成>= <= 就減一就可以了
列出不等式:
S[a-1]-S[a+b]<=-c-1
S[a+b]-S[a-1]<=c-1
需要注意的是,不是每次添加附加結點0都是正確的,要保證添加的點是不會使用到的,比如n+1
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define inf 0x3f3f3f3f#define eps 1e-6#define ll __int64using namespace std;struct node{ int v,w,next;}e[10010];int n,m,h,head[110],d[110],inq[110],outq[110];void init(){ memset(head,-1,sizeof head); h=0;}void addedge(int a,int b,int c){ e[h].v=b; e[h].w=c; e[h].next=head[a]; head[a]=h++;}int spfa(int st){ memset(d,0x3f,sizeof d); memset(inq,0,sizeof inq); memset(outq,0,sizeof outq); // d[st]=0;inq[st]=1; queue<int> q; q.push(st); for(int i=1;i<=n;i++) { inq[i]=1; q.push(i); } while(!q.empty()) { int x=q.front(); q.pop(); inq[x]=0; outq[x]++; if(outq[x]>n+1) return 0;//存在負環//是在與源點連通的圖上有負環 for(int i=head[x];i!=-1;i=e[i].next) { if(d[e[i].v]>d[x]+e[i].w) { d[e[i].v]=d[x]+e[i].w; if(!inq[e[i].v]) { inq[e[i].v]=1; q.push(e[i].v); } } } } return 1;}int main(){ int a,b,c; char s[10]; while(scanf("%d",&n)&&n) { init(); scanf("%d",&m); while(m--) { scanf("%d%d%s%d",&a,&b,s,&c); if(s[0]=='g') addedge(b+a,a-1,-c-1); else addedge(a-1,b+a,c-1); } // for(int i=0;i<=n;i++) // addedge(0,i,0); int ans=spfa(0); if(ans) printf("lamentable kingdom\n"); else printf("successful conspiracy\n"); } return 0;}