poj 1364
http://poj.org/problem?id=1364
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define maxn 51000
using namespace std; const int inf=<<;
struct node
{
int u,v,c;
node(){}
node(int u,int v,int c):u(u),v(v),c(c){}
}p[maxn];
int head[maxn],next[maxn],cnt[maxn];
bool vis[maxn];
int e,n,m,top;
int dis[maxn]; void addnode(int u,int v,int c)
{
p[e]=node(u,v,c);
next[e]=head[u];head[u]=e++;
} bool relax(int u,int v,int c)
{
if(dis[v]>dis[u]+c)
{
dis[v]=dis[u]+c;
return true;
}
return false;
} void inti()
{
memset(head,-,sizeof(head));
memset(next,-,sizeof(next));
e=;
top=-;
for(int i=; i<m; i++)
{
int a,b,c;
char s[];
scanf("%d %d %s %d",&a,&b,s,&c);
if(!strcmp(s,"gt")){
addnode(a+b,a-,(-c-));
}
else if(!strcmp(s,"lt")){
addnode(a-,a+b,c-);
}
}
}
int a[maxn];
bool spfa()
{
int i;
memset(cnt,,sizeof(cnt));
for(i=; i<=n+; i++) {dis[i]=inf;vis[i]=;}
for(i=; i<n; i++)
{
a[++top]=i;
vis[i]=true;
}
dis[]=;
while(top>-)
{
int pre=a[top--];
vis[pre]=false;
for(int i=head[pre]; i!=-; i=next[i])
{
if(relax(pre,p[i].v,p[i].c)&&!vis[p[i].v])
{
if((++cnt[p[i].v])>(n)) return false;
a[++top]=p[i].v;
vis[p[i].v]=true;
}
}
}
return true;
} int main()
{
while(scanf("%d",&n)&&n)
{
scanf("%d",&m);
inti();
if(spfa()) printf("lamentable kingdom\n");
else printf("successful conspiracy\n");
}
return ;
}
poj 1364的更多相关文章
- POJ 1364 / HDU 3666 【差分约束-SPFA】
POJ 1364 题解:最短路式子:d[v]<=d[u]+w 式子1:sum[a+b+1]−sum[a]>c — sum[a]<=sum[a+b+1]−c−1 ...
- poj 1364 King(差分约束)
题目:http://poj.org/problem?id=1364 #include <iostream> #include <cstdio> #include <cst ...
- POJ 1364 King
http://poj.org/problem?id=1364 题意 :给出一个序列a1,a2,a3,a4.....ai,......at ;然后给你一个不等式使得ai+a(i+1)+a(i+2)+.. ...
- POJ 1364 King (UVA 515) 差分约束
http://poj.org/problem?id=1364 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...
- poj 1364 King(差分约束)
题意(真坑):傻国王只会求和,以及比较大小.阴谋家们想推翻他,于是想坑他,上交了一串长度为n的序列a[1],a[2]...a[n],国王作出m条形如(a[si]+a[si+1]+...+a[si+ni ...
- POJ 1364 King --差分约束第一题
题意:求给定的一组不等式是否有解,不等式要么是:SUM(Xi) (a<=i<=b) > k (1) 要么是 SUM(Xi) (a<=i<=b) < k (2) 分析 ...
- poj 1364 差分约束
思路:设dis[i]为从0点到第i点的序列总和.那么对于A B gt k 来讲意思是dis[B+A]-dis[A]>k; 对于A B lt k来讲就是dis[B+A]-dis[A]<k; ...
- [poj 1364]King[差分约束详解(续篇)][超级源点][SPFA][Bellman-Ford]
题意 有n个数的序列, 下标为[1.. N ], 限制条件为: 下标从 si 到 si+ni 的项求和 < 或 > ki. 一共有m个限制条件. 问是否存在满足条件的序列. 思路 转化为差 ...
- poj 1364 King(线性差分约束+超级源点+spfa判负环)
King Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14791 Accepted: 5226 Description ...
随机推荐
- url传递中文的解决方案
本文转载:http://www.cnblogs.com/ghd258/archive/2005/10/23/260241.html url传递中文的解决方案 1.设置web.config文件. < ...
- NDN路由--OSPFN安装与配置
现在的IP网络的问题已经暴露的很多了,各种改进的网络架构与设想非常多,但其中以基于内容为中心的网络发展最为迅速,其中,NDN的架构最为完整,代码也比较成熟.OSPFN是基于CCNX的,所以之前要安装C ...
- [PWA] 12. Intro to IndexedDB
Use the library indexedDB-promised. Create a database and stroe: import idb from 'idb'; // Open(db_n ...
- android高效ORM数据库框架greenDao使用
因为项目中多处用到了数据库,需要对数据库频繁的读写操作,虽然android 自带的SQLiteOpenHelper的.这种方式比较方便易懂,但是在使用过程中需要写很多的sql语句,而且需要及时的关闭和 ...
- python 之路,Day11 (下)- sqlalchemy ORM
python 之路,Day11 - sqlalchemy ORM 本节内容 ORM介绍 sqlalchemy安装 sqlalchemy基本使用 多外键关联 多对多关系 表结构设计作业 1. ORM ...
- 使用EF 的简单的增删改查
using DAL; using Model; using System; using System.Collections.Generic; using System.Linq; using Sys ...
- 将datagrid中数据导出到excel中 -------<<工作日志2014-6-6>>
前台datagrid数据绑定 #region 导出到excel中 /// <summary> /// 2014-6-6 /// </summary> / ...
- 面试题——分析从输入url到页面返回的过程(或者查询返回过程)
1. You enter a URL into the browser(输入一个url地址) 2.The browser looks up the IP address for the domain ...
- NPOI对excel文件的导入导出
现理解:将一个Excel文件(工作簿-IWorkBook)看做是一个你要操作的对象,每个工作簿包含多个工作表(ISheet)对象,每个工作表中又包含多个行对象(IRow),每行又包含多个单元格(ICe ...
- 使用NPOI插件读取excel模版修改数据后保存到新目录新文件中
添加引用: using System.IO; using NPOI.XSSF.UserModel; using NPOI.SS.UserModel; using NPOI.HSSF.UserModel ...