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]中(无需跨过其它点存 ...
随机推荐
- pch文件的作用和配置
pch文件说白了就是一个头文件,只不过这个头文件的类在全局都可以使用,所以说非常的方便,并不用在每个类里面都写一些重复类的头文件,只要将用到的类的头文件放到pch文件里面就行了,当然了还有就是宏定义, ...
- 一个问题:关于finally中return吞掉catch块中抛出的异常
今天遇到一个感觉很神奇的问题,记录一下问题以及自己分析问题的思路. 预警:不知道怎么看java字节码的朋友可能需要先看一下如何阅读java字节码才能看懂后面的解释. 我有一段程序: public cl ...
- 微信小程序入门——怎么建多个项目?(导入官方Demo程序进行学习)
昨天1月9日微信小程序发布,顿时被朋友圈刷爆,今天看了一下官方文档,自己开始一步一步搭建环境体验小程序开发. 常见问题: 1.微信小程序开发是否需要重新创建开发者账号? 需要,即使之前申请了微信服务号 ...
- bzoj3504: [Cqoi2014]危桥 网络流
一种网络流建图的思路吧,改天最好整理一波网络流建图思路 #include <bits/stdc++.h> using namespace std; int n,h,t,a1,a2,an,b ...
- scapy流量嗅探简单使用
官方文档:http://scrapy-chs.readthedocs.io/zh_CN/latest/index.html 参考链接:http://blog.csdn.net/Jeanphorn/ar ...
- 原生js
- 传统flv网页视频(flvplayer)--兼容
1.flv网页视频 项目中需要web打开视频,百度搜了好几个插件,本来是打算用H5 vedio,但是客户的浏览器用的比较老,如果用H5标签的话,IE9以下的浏览器是不支持的.所以费劲又去找了其他插件. ...
- kmp//呵呵!看毛片算法
以前刚学的时候迷迷糊糊的,一看就懵圈,前几天捡起来的时候 发现还不会 于是研究了两天,自尊心严重受挫,今天的时候 突然一道灵光迸发,居然 感觉好像懂了,于是又琢磨起来 终于 我懂了 呵呵! ...
- 使用pycharm+pyqt5 触发自定义方法
1.依旧使用上次QtDesigner做的界面,如下图: 2.本次的使用text Browser 和 text Edit 和 pushButton控件做触发联系: 3.目的实现在text Edit中随意 ...
- Spring in Action --- 第二章 装配Bean
Spirng配置的可选方案 在XML中进行显示配置 在Java中进行显示配置 隐式的bean发现机制和自动装配 bean装配 1. 在希望被扫描到的类上加注解 @Component 2. 基于不同的配 ...