日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poj1364 King

發(fā)布時間:2024/10/12 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj1364 King 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

地址:http://poj.org/problem?id=1364

題目:

King
Time Limit:?1000MS?Memory Limit:?10000K
Total Submissions:?13466?Accepted:?4793

Description

Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound king.'' After nine months her child was born, and indeed, she gave birth to a nice son.?
Unfortunately, as it used to happen in royal families, the son was a little retarded. After many years of study he was able just to add integer numbers and to compare whether the result is greater or less than a given integer number. In addition, the numbers had to be written in a sequence and he was able to sum just continuous subsequences of the sequence.?

The old king was very unhappy of his son. But he was ready to make everything to enable his son to govern the kingdom after his death. With regards to his son's skills he decided that every problem the king had to decide about had to be presented in a form of a finite sequence of integer numbers and the decision about it would be done by stating an integer constraint (i.e. an upper or lower limit) for the sum of that sequence. In this way there was at least some hope that his son would be able to make some decisions.?

After the old king died, the young king began to reign. But very soon, a lot of people became very unsatisfied with his decisions and decided to dethrone him. They tried to do it by proving that his decisions were wrong.?

Therefore some conspirators presented to the young king a set of problems that he had to decide about. The set of problems was in the form of subsequences Si = {aSi, aSi+1, ..., aSi+ni} of a sequence S = {a1, a2, ..., an}. The king thought a minute and then decided, i.e. he set for the sum aSi + aSi+1 + ... + aSi+ni of each subsequence Si an integer constraint ki (i.e. aSi + aSi+1 + ... + aSi+ni < ki or aSi + aSi+1 + ... + aSi+ni > ki resp.) and declared these constraints as his decisions.?

After a while he realized that some of his decisions were wrong. He could not revoke the declared constraints but trying to save himself he decided to fake the sequence that he was given. He ordered to his advisors to find such a sequence S that would satisfy the constraints he set. Help the advisors of the king and write a program that decides whether such a sequence exists or not.?

Input

The input consists of blocks of lines. Each block except the last corresponds to one set of problems and king's decisions about them. In the first line of the block there are integers n, and m where 0 < n <= 100 is length of the sequence S and 0 < m <= 100 is the number of subsequences Si. Next m lines contain particular decisions coded in the form of quadruples si, ni, oi, ki, where oi represents operator > (coded as gt) or operator < (coded as lt) respectively. The symbols si, ni and ki have the meaning described above. The last block consists of just one line containing 0.

Output

The output contains the lines corresponding to the blocks in the input. A line contains text successful conspiracy when such a sequence does not exist. Otherwise it contains text lamentable kingdom. There is no line in the output corresponding to the last ``null'' block of the input.

Sample Input

4 2 1 2 gt 0 2 2 lt 2 1 2 1 0 gt 0 1 0 lt 0 0

Sample Output

lamentable kingdom successful conspiracy

Source

Central Europe 1997 思路:   從前綴和的角度考慮,每個給出的條件都是一個不等式。   如: 1 2 gt 0 => s3-s1>0 => s3-s1>=1     2 2 lt 2 => s4-s2<2 => s4-s2<=1   這樣問題變成了判斷這個不等式組是否成立的問題了,也是差分約束問題。   跑個 最長路,看有沒有環(huán)就好了。為了防止圖不連通,增加一個超級原點,從原點到其他點建一條權值為0的邊。   對了,別用vector存邊,會T。 1 #include <cstdio> 2 #include <algorithm> 3 #include <cmath> 4 #include <queue> 5 using namespace std; 6 7 #define MP make_pair 8 #define PB push_back 9 typedef long long LL; 10 typedef pair<int,int> PII; 11 const double eps=1e-8; 12 const double pi=acos(-1.0); 13 const int K=1e6+7; 14 const int mod=1e9+7; 15 16 struct node 17 { 18 int to,v,next; 19 }edge[K]; 20 int tot,head[K]; 21 void add(int x,int y,int z) 22 { 23 edge[tot].to=y,edge[tot].v=z,edge[tot].next=head[x]; 24 head[x]=tot++; 25 } 26 int n,m,vis[K],dis[K],cnt[K]; 27 int spfa(int st) 28 { 29 queue<int>q; 30 q.push(st),vis[st]=1,dis[st]=1,cnt[st]=1; 31 while(q.size()) 32 { 33 int u=q.front(); 34 vis[u]=0;q.pop(); 35 for(int i=head[u];~i;i=edge[i].next) 36 { 37 int v=edge[i].to,w=edge[i].v; 38 if(dis[v]<dis[u]+w) 39 { 40 dis[v]=dis[u]+w; 41 if(vis[v]) continue; 42 if(cnt[v]>n) return 1; 43 q.push(v),vis[v]=1,cnt[v]++; 44 } 45 } 46 } 47 return 0; 48 } 49 int main(void) 50 { 51 char ss[20]; 52 while(~scanf("%d%d",&n,&m)&&n) 53 { 54 tot=0; 55 for(int i=0;i<=n+1;i++) 56 head[i]=-1,vis[i]=0,dis[i]=0,cnt[i]=0; 57 for(int i=1,u,v,w;i<=m;i++) 58 { 59 scanf("%d%d%s%d",&u,&v,ss,&w); 60 if(ss[0]=='g') add(u-1,u+v,w+1); 61 else add(u+v,u-1,1-w); 62 } 63 for(int i=0;i<=n;i++) 64 add(n+1,i,0); 65 if(spfa(n+1)) 66 printf("successful conspiracy\n"); 67 else 68 printf("lamentable kingdom\n"); 69 } 70 return 0; 71 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/weeping/p/6973390.html

總結(jié)

以上是生活随笔為你收集整理的poj1364 King的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。