日韩性视频-久久久蜜桃-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)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩视频在线观看视频 | 一区二区三区四区亚洲 | 欧美色图一区二区 | 伊人网在线免费观看 | 日韩经典一区二区三区 | 2022国产精品| 伊人久久大香线蕉av一区 | 免费久久网站 | 成人三级电影网站 | 亚洲一区高清 | 不卡中文字幕 | 亚洲精品视频播放 | 日韩激情文学 | 九九色网站 | 国产一级影片 | 欧美一级片在线视频 | 欧美性生活在线视频 | 日本一区免费视频 | 亚洲91网站 | 高清日韩欧美 | 久久96视频| 欧美精品一区二区三区久久 | 人妻无码一区二区三区久久 | 亚洲成a人v欧美综合天堂麻豆 | 男人爽女人下面动态图 | 亚洲精品3 | 特黄特色大片免费播放器使用方法 | 黄色茄子视频 | wwwjavhd| 国产无套内射普通话对白 | 女人叫床很黄很污句子 | 亚洲系列在线观看 | 制服丝袜一区二区三区 | www.白丝 | 91免费高清视频 | 欧美嘿咻视频 | 中文字幕第六页 | www日日| 国产午夜成人久久无码一区二区 | 在线cao | 色爽视频 | 不卡av一区 | 亚洲视频免费播放 | 夜夜综合| 性生活视屏 | 手机看片一区二区三区 | 成人a级网站 | 波多野一区二区三区 | 久久天天操 | 色欧美88888久久久久久影院 | 国产精品国产三级国产专播精品人 | 亚洲人一区 | 97视频在线观看免费 | 日日拍夜夜拍 | 91视频福利 | 精品国产午夜福利 | 欧美一区二区 | 精品久久久久久久久久久久久 | 日本中文字幕在线 | 国产精品美女www | 狠狠cao日日穞夜夜穞av | 性感美女在线 | 久操视频精品 | 男人的天堂黄色 | 无套内谢老熟女 | 欧洲熟妇的性久久久久久 | 亚洲AV成人无码久久 | av一级久久 | 综合色亚洲 | 91精品一区二区 | 成年人黄国产 | 在线播放日韩av | 国产www精品| 日本japanese丰满白浆 | 欧美精品在线观看一区二区 | 综合在线亚洲 | 国产日韩欧美不卡 | 污污的视频网站在线观看 | 青青久久国产 | 美女视频一区二区 | 一级全黄少妇性色生活片 | 四虎久久久 | 草草草av| 99国产精品一区二区三区 | 伊人av网站 | 91中文在线观看 | 天堂资源在线观看 | k8经典成人理伦片 | 国产精品粉嫩 | av高清在线| 日韩一区二区在线视频 | 午夜精品久久久久久久久久 | 伊人一级 | www.国产麻豆 | 性做久久久久久久久久 | 色妞av| 97人人超 | 一区二区三区四区五区在线视频 | 日韩三级欧美 |