hdu 1531 King
首先吐槽一下这个题目的题意描述,我看了半天才明白。 下标全部都是乱标的!!!!出题者能不能规范一点下标的写法!!!!
差分约束系统
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; int n,m,tyu;
const int maxn=;
const int INF=0x7FFFFFFF;
struct abc
{
int startt;
int endd;
int costt;
} node[maxn];
vector<abc>ljb[maxn];
int ff[maxn],summ[maxn],dist[maxn]; void spfa()
{
queue<int>Q;
while(!Q.empty()) Q.pop();
int i;
for(i=; i<=n+; i++) dist[i]=INF;
memset(ff,,sizeof(ff));
memset(summ,,sizeof(summ));
dist[]=;
ff[]=;
Q.push();
while(!Q.empty())
{
int hh=Q.front();
Q.pop();
summ[hh]++;
if(summ[hh]>n+)
{
tyu=;
break;
}
ff[hh]=;
for(i=; i<ljb[hh].size(); i++)
{
abc noww;
noww=ljb[hh][i];
if(dist[hh]+noww.costt<dist[noww.endd])
{
dist[noww.endd]=dist[hh]+noww.costt;
if(ff[noww.endd]==)
{
ff[noww.endd]=;
Q.push(noww.endd);
}
}
}
}
}
int main()
{
int i,si,ni,ki,tott;
char oi[];
while(~scanf("%d",&n))
{
if(n==) break;
scanf("%d",&m);
tott=;
for(i=; i<=n+; i++) ljb[i].clear();
for(i=; i<m; i++)
{
scanf("%d%d%s%d",&si,&ni,oi,&ki);
if(strcmp("lt",oi)==)
{
node[tott].startt=si;
node[tott].endd=si+ni+;
node[tott].costt=ki-;
ljb[si].push_back(node[tott]);
tott++;
}
else if(strcmp("gt",oi)==)
{
node[tott].startt=si+ni+;
node[tott].endd=si;
node[tott].costt=-(ki+);
ljb[si+ni+].push_back(node[tott]);
tott++;
}
}
for(i=; i<=n+; i++)
{
node[tott].startt=;
node[tott].endd=i;
node[tott].costt=;
ljb[].push_back(node[tott]);
tott++;
}
tyu=;
spfa();
if(tyu==) printf("successful conspiracy\n");
else printf("lamentable kingdom\n");
}
return ;
}
hdu 1531 King的更多相关文章
- hdu 1531 king(差分约束)
King Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1531(差分约束)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1531 差分约束的题之前也碰到过,刚好最近正在进行图论专题的训练,就拿来做一做. ①:对于差分不等式,a ...
- HDU 5642 King's Order dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 King's Order Accepts: 381 Submissions: 1361 ...
- HDU 5644 King's Pilots 费用流
King's Pilots 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5644 Description The military parade w ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDU 5642 King's Order 动态规划
King's Order 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 Description After the king's speec ...
- HDU 5640 King's Cake GCD
King's Cake 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5640 Description It is the king's birthd ...
- HDU 5641 King's Phone 模拟
King's Phone 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5641 Description In a military parade, ...
- hdu 5641 King's Phone
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5641 题目类型:水题 题目思路:将点x到点y所需要跨过的点存入mark[x][y]中(无需跨过其它点存 ...
随机推荐
- C++ 头文件系列(queue)
简介 这个头文件定义了两个跟队列有关的类----quque.priority_queue,分别实现的是队列 和 优先队列这两个概念. 但是与这两个类模版与其它类模版(vector.array等)最大的 ...
- 使用Netsil监控Kubernetes上的微服务
ubernetes是容器编排和调度领域的王者,它击败了竞争对手Docker Swarm和Apache Mesos,开启了闪耀的未来,微服务可以自修复,可以自动扩展,可以跨zone,region甚至跨云 ...
- Java线程如何返回数据
前言 当开发者从单线程开发模式过渡到多线程环境,一个比较棘手的问题就是如何在一个线程中返回数据,众所周知,run()方法和start()方法不会返回任何值. 笔者在学习<Java Network ...
- Zabbix-agent使用自带模板监控 MySQL
1.rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm 2.yum ...
- oracle数据库一些用户管理语句
查询所有数据库用户 select * from dba_users 查看数据库名称 select name from v$database 查看权限 select * from user_sys_pr ...
- GroupingView点击分组标题不展开,或点击标题部分文字不展开
GroupingView结构: 分组标题groupTextTpl是用两个DIV 来进行修饰的,在mouseDown时,EXT会查找css class=".x-grid-group-hd ...
- java系统参数
package com.test; import java.sql.SQLException; import java.util.Properties; import com.mchange.v2.c ...
- CODE[VS]-寻找子串位置-字符串处理-天梯青铜
题目描述 Description 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置. 输入描述 Input Description 仅一行包含两个字符串a和b 输出描述 ...
- qwt的安装与使用
qwt简介 QWT,全称是Qt Widgets for Technical Applications,是一个基于LGPL版权协议的开源项目, 可生成各种统计图. 具体介绍,可参看官方网址:http:/ ...
- js关于setTimeout传参
setTimeout函数有两个参数,都是必须的,一个是要执行的函数,一个是延时的时间 第一个参数: 要执行的函数,一般来说是可以执行的,但是这里遇到一个问题,就是如果变量是个数组的话, 如果数组为nu ...