King

来源:互联网 发布:新浪微博数据库 编辑:程序博客网 时间:2024/05/01 22:35

http://162.105.81.212/JudgeOnline/problem?id=1364

Description

Once, inone kingdom, there was a queen and that queen was expecting a baby. Thequeen prayed: ``If my child was a son and if only he was a soundking.'' After nine months her child was born, and indeed, she gavebirth to a nice son.
Unfortunately, as it used to happen in royal families, the sonwas a little retarded. After many years of study he was able just toadd integer numbers and to compare whether the result is greater orless than a given integer number. In addition, the numbers had to bewritten in a sequence and he was able to sum just continuoussubsequences of the sequence.

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

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

Therefore some conspirators presented to the young king a set ofproblems that he had to decide about. The set of problems was in theform 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. heset for the sum aSi + aSi+1 + ... + aSi+ni of each subsequence Si aninteger constraint ki (i.e. aSi + aSi+1 + ... + aSi+ni < ki or aSi +aSi+1 + ... + aSi+ni > ki resp.) and declared these constraints ashis decisions.

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

Input

Theinput consists of blocks of lines. Each block except the lastcorresponds to one set of problems and king's decisions about them. Inthe 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 thenumber of subsequences Si. Next m lines contain particular decisionscoded in the form of quadruples si, ni, oi, ki, where oi representsoperator > (coded as gt) or operator < (coded as lt)respectively. The symbols si, ni and ki have the meaning describedabove. The last block consists of just one line containing 0.

Output

Theoutput contains the lines corresponding to the blocks in the input. Aline contains text successful conspiracy when such a sequence does notexist. Otherwise it contains text lamentable kingdom. There is no linein 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

又是WA了n次的题目,主要错误有三个:一是构图时大于,小于搞反了,明知道这里可能会出错,还是不愿先用在纸上模拟一下,
S[b] <= S[a] + k , 在图中加一条由a指向b权值为k的单向边.二是不能想解决Interval时只用添加最后一个节点入队列就可以了,
要添加所有的节点入队列,三是不是n个节点,是n+1个节点,所以在判断有负环应该大于n而不是大于等于n.

学差分约束系统,核心就是学如何构图,如何发现它可以用图来表示。
目前碰到的题目主要特征是 ,有区间,大于小于,至少,至多 , 这几个关键字,构图时用Sigma(b) - Sigma(a)表示区间,
把区间内的各个点变成顶点.

原创粉丝点击