poj 1364
(1)題意:
有乙個序列長度為n,給出m次的約數,詢問這m次限定能否確定乙個序列。
輸入n,m
然後m行,每行有四個引數si,ni,oi,ki
如果oi是gt就是》,否則是<.
如果最後能確定乙個序列就輸出「lamentable kingdom」,
否則輸出「successful conspiracy」。
(2)思路:
如果是》,就是s[si+ni]-s[si-1]>k,
否則s[si+ni]-s[si-1]將它轉化為最短路,
s[si-1]-s[si+ni]<=-z-1
s[si+ni] - s[si-1] <=z-1
然後再將所有點建立乙個源點為n+1的圖,判斷是否存在負環就好了。
(3)**:
(最短路求負環)
#include#include#include#include#includeusing namespace std;
const int maxn = 105;
const int inf = 1e9+10;
int head[maxn],tot,vis[maxn],tim[maxn],dis[maxn],n,m,st[maxn<<2];
struct nodecur[maxn<<2];
void init()
void add(int x,int y,int z);
head[x] = tot++;
}bool spfa()
int top = 0;
st[top++] = n+1;dis[n+1] = 0;tim[n+1]++;
while(top!=0)
}} }
return true;
}int main(void)cur[maxn<<2];
void init()
void add(int x,int y,int z);
head[x] = tot++;
}bool spfa()
int top = 0;
st[top++] = n+1;tim[n+1]++;dis[n+1] = 0;
while(top!=0)
}} }
return true;
}int main(void)
for(int i=0;i<=n;i++)
if(spfa()==true) printf("lamentable kingdom\n");
else printf("successful conspiracy\n");
} return 0;
}
差分約束系統 POJ 1364
參考 html 所謂查分約束系統其實很簡單,就是全都是兩個未知數的差小於等於某個常數 大於等於 也可以,因為左右乘以 1就可以化成小於等於 的一系列方程組 ax p,a 1或 1 如 x1 x2 0 x1 x5 1 x2 x5 3 x3 x2 5 x4 x3 4 x4 x3 12 x5 x1 23 ...
poj1364(差分約束系統)
poj1364 設s i 表示a1 a2 a i 1 的和 給我們n個點,m條約束 如果是a b gt c 那麼表示 s a b 1 s a c s a s a b 1 c c 1 s a s a b 1 c 1 如果是a b lt c 那麼表示 s a b 1 s a c s a b 1 s a ...
POJ 1364 差分約束
解題的思路比較奇葩。第一次見到啊,也不知道別人是怎麼看出來這種情況下就是差分約束也就是可以用到圖論,表示真的好迷啊。看來對差分約束的概念還很差呢。include include include include includeusing namespace std const int maxn 100...