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

正解:SPFA+差分约束系统

解题报告:

  题目大意是给定一段区间的和小于或者大于某个值,然后问是否存在这种序列。

  考虑用点做差分约束的话感觉无从下手,于是我们可以想到用前缀和的形式,首末来加边。比如Sy-Sx-1<=z 则添加一条x-1到y的权值为z的边

  然后这道题比较水,我们只需要判断是否存在负权环就可以了。值得一提的是我们需要一开始就把所有结点加进队列,并且把所有的dis置为0就可以了。因为只要存在负权环就一定会不断入队,判断一下次数大于某个值就可以break了

 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#ifdef WIN32
#define OT "%I64d"
#else
#define OT "%lld"
#endif
using namespace std;
typedef long long LL;
const int inf = (<<);
const int MAXN = ;
const int MAXM = ;
int n,m;
int dis[MAXN];
int first[MAXN],to[MAXM],next[MAXM],w[MAXM];
int ecnt;
queue<int>Q;
char ch[];
bool pd[MAXN];
int cnt[MAXN]; inline int getint()
{
int w=,q=;
char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar();
if (c=='-') q=, c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar();
return q ? -w : w;
}
inline void Init(){
memset(first,,sizeof(first));
ecnt=;
memset(pd,,sizeof(pd));
while(!Q.empty()) Q.pop();
memset(cnt,,sizeof(cnt));
} inline bool spfa(){
for(int i=;i<=n;i++) Q.push(i),pd[i]=;
for(int i=;i<=n;i++) dis[i]=;
while(!Q.empty()){
int u=Q.front(); Q.pop(); pd[u]=;
for(int i=first[u];i;i=next[i]){
int v=to[i];
if(dis[v]>dis[u]+w[i]) {
dis[v]=dis[u]+w[i];
if(!pd[v]) {
cnt[v]++;
if(cnt[v]>=n) return false;
Q.push(v); pd[v]=;
}
}
}
}
return true;
} inline void solve(){
while(true){
n=getint();
if(n==) break;
m=getint();
Init();
int x,y,z;
for(int i=;i<=m;i++) {
x=getint();y=getint(); scanf("%s",ch); z=getint();
if(ch[]!='g') { next[++ecnt]=first[x-];to[ecnt]=x+y;first[x-]=ecnt;w[ecnt]=z-; }
else{ next[++ecnt]=first[x+y];to[ecnt]=x-;first[x+y]=ecnt;w[ecnt]=-z-; }
}
if(!spfa()) printf("successful conspiracy\n");
else printf("lamentable kingdom\n");
}
} int main()
{
solve();
return ;
}

POJ1364 King的更多相关文章

  1. 转自作者:phylips@bmy

    差分约束系统 2008-11-28 20:53:25|  分类: 算法与acm|举报|字号 订阅     出处:http://duanple.blog.163.com/blog/static/7097 ...

  2. poj图论解题报告索引

    最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...

  3. ZOJ1260/POJ1364国王(King)

    // 题意 问是否存在一个长度为n的序列// 这个序列满足m个限制// 每个限制有 si ni oi kisi 为序列位置 ni为从si开始连续长度为ni+1 的子序列 这些子序列和 大于或小于 ki ...

  4. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  5. [bzoj1087][scoi2005]互不侵犯king

    题目大意 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上 左下右上右下八个方向上附近的各一个格子,共8个格子. 思路 首先,搜索可以放弃,因为这是一 ...

  6. King's Quest —— POJ1904(ZOJ2470)Tarjan缩点

    King's Quest Time Limit: 15000MS Memory Limit: 65536K Case Time Limit: 2000MS Description Once upon ...

  7. 【状压DP】bzoj1087 互不侵犯king

    一.题目 Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上.下.左.右,以及左上.左下.右上.右下八个方向上附近的各一个格子,共8个格子. I ...

  8. ZOJ 2334 Monkey King

    并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子                       Monkey King ...

  9. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 K. King’s Rout

    K. King's Rout time limit per test 4 seconds memory limit per test 512 megabytes input standard inpu ...

随机推荐

  1. 使用Unity3D引擎开发赛车游戏

    Car Tutorial 在Unity3D的Asset Store有一个赛车的Demo —— Car Tutorial,看起来特别酷的赛车游戏Demo,不过我还没有下载下来,因为在公司下载Assets ...

  2. JMeter学习(二)录制脚本

    ---------------------------------------------------------------------------------------------------- ...

  3. Linux 安装oracle客户端

    环境: CentOS release 6.4 (Final) 一.下载文件 1.首先要查看oracle版本,对应的SQL如下:  select * from V$version ; 2.根据oracl ...

  4. 转: Github访问慢解决办法

    from: https://yq.aliyun.com/articles/36744 Github访问慢解决办法   zxiaofan 2016-04-20 17:25:00 浏览2156 评论0 摘 ...

  5. Java中是否可以继承String类,为什么

    Java中,是否可以继承String类?为什么? 答案: 不可以,因为String类有final修饰符,而final修饰的类是不能被继承的,实现细节不允许改变. public final class ...

  6. 【Asp.Net】Asp.Net CommandName作用

    数据绑定控件的模板中 CommandName 属性以下属性值会触发特定的事件: Cancel(取消) Delete(删除) Select(选择) Edit(编辑) Insert(插入) Update( ...

  7. 未能加载文件或程序集“XXXXX”或它的某一个依赖项。试图加载格式不正确的程序。

    未能加载文件或程序集“FastColoredTextBox, Version=2.10.5.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项.试图加载 ...

  8. Console的使用——Google Chrome代码调试

    Google Chrome控制台为开发者提供了网页和应用程序调试的几种方法,本文通过基本操作.控制台API.命令行API来介绍控制台的使用. 基本操作 1.开启控制台     可以通过下列三种方式开启 ...

  9. Android 自定义NumProgressBar

    这是GitHub上的一个开源控件,由于作者是用Android Studio开发,直接导入Eclipse不能使用,这边抠出来这个功能,做成一个小Demo,供Eclipse平台使用. style配置文件中 ...

  10. IOS开发之——意见反馈UITextView的使用+不能输入字符输入

    @interface DMFeedbackViewController ()<UITextViewDelegate,UIAlertViewDelegate>@property (nonat ...