hdu1384Intervals(差分约束)
#include <bits/stdc++.h>
using namespace std; const int maxn = 5e4 + ;
const int inf = 0x3f3f3f3f;
int n, head[maxn], dis[maxn], cnt;
struct node{
int to, w, next;
} ed[maxn*]; //数组开2*maxn超时,开大一点
inline void add( int u, int v, int w ){
ed[cnt].to = v;
ed[cnt].w = w;
ed[cnt].next = head[u];
head[u] = cnt++;
} inline int max( int a, int b ){
return a>b ? a:b;
} inline int min( int a, int b ){
return a<b ? a:b;
} inline void spfa( int beg ){
bool vis[maxn];
memset( vis, , sizeof(vis) );
memset( dis, -inf, sizeof(dis) );
queue<int> q;
q.push(beg);
dis[beg] = ;
vis[beg] = ;
while( !q.empty() ){
int u = q.front();
q.pop();
vis[u] = ;
for( int i=head[u]; i!=-; i=ed[i].next ){
int v = ed[i].to;
if( dis[v] < dis[u]+ed[i].w ){
dis[v] = dis[u]+ed[i].w;
if( !vis[v] ){
vis[v] = ;
q.push(v);
}
}
}
}
} int main(){
while( ~scanf("%d", &n) ){
cnt = ;
int a = inf, b = -;
memset( head, -, sizeof(head) );
for( int i=; i<n; i++ ){
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
add( u, v+, w );
a = min( a, u );
b = max( b, v+ );
}
for( int i=a; i<=b; i++ ){
add( i-, i, );
add( i, i-, - );
}
spfa(a);
printf("%d\n", dis[b]);
} return ;
}
hdu1384Intervals(差分约束)的更多相关文章
- Hdu1384-Intervals(差分约束)
Problem Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.Wr ...
- Candies-POJ3159差分约束
Time Limit: 1500MS Memory Limit: 131072K Description During the kindergarten days, flymouse was the ...
- poj3159 差分约束 spfa
//Accepted 2692 KB 1282 ms //差分约束 -->最短路 //TLE到死,加了输入挂,手写queue #include <cstdio> #include & ...
- ZOJ 2770火烧连营——差分约束
偶尔做了一下差分约束. 题目大意:给出n个军营,每个军营最多有ci个士兵,且[ai,bi]之间至少有ki个士兵,问最少有多少士兵. ---------------------------------- ...
- POJ 2983 Is the Information Reliable? 差分约束
裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...
- 2014 Super Training #6 B Launching the Spacecraft --差分约束
原题:ZOJ 3668 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3668 典型差分约束题. 将sum[0] ~ sum ...
- POJ 1364 King --差分约束第一题
题意:求给定的一组不等式是否有解,不等式要么是:SUM(Xi) (a<=i<=b) > k (1) 要么是 SUM(Xi) (a<=i<=b) < k (2) 分析 ...
- [USACO2005][POJ3169]Layout(差分约束)
题目:http://poj.org/problem?id=3169 题意:给你一组不等式了,求满足的最小解 分析: 裸裸的差分约束. 总结一下差分约束: 1.“求最大值”:写成"<=& ...
- ShortestPath:Layout(POJ 3169)(差分约束的应用)
布局 题目大意:有N头牛,编号1-N,按编号排成一排准备吃东西,有些牛的关系比较好,所以希望他们不超过一定的距离,也有一些牛的关系很不好,所以希望彼此之间要满足某个关系,牛可以 ...
随机推荐
- Xamarin Assets文件读取
在Assets文件夹中添加nlog.config文件,在属性中将Build Action设置为AndroidAsset var steam = Assets.Open("nlog.confi ...
- 工具分享:excel2json,将Excel表格转换为JSON
此次分享的是github上的一个开源小工具:excel2json,用于把Excel表转换成json对象,并保存到一个文本文件. 项目地址:https://github.com/neil3d/excel ...
- cmake安装与使用
CMake(cross platform make)是一个开源的跨平台工具系列,旨在构建,测试和打包软件. 使用指定名为CMakeLists.txt的配置文件可以控制软件的构建.测试和打包等流程. 通 ...
- 【视频开发】ONVIF、RTSP/RTP、FFMPEG的开发实录
ONVIF.RTSP/RTP.FFMPEG的开发实录 前言 本文从零基础一步步实现ONVIF协议.RTSP/RTP协议获取IPC实时视频流.FFMPEG解码.开发环境为WIN7 32位 + VS201 ...
- 图论 --- 三维空间bfs
<传送门> [题目大意] 给你一个三维的迷宫,让你计算从入口走到出口最少步数. [题目分析] 其实和二维迷宫还是一样的,还是用队列来做,由于BFS算法一般是不需要回溯的,所以我们就用不着还 ...
- Spark学习(3) SparkSQL
什么事sparkSQL Spark SQL是Spark用来处理结构化数据的一个模块,它提供了一个编程抽象叫做DataFrame并且作为分布式SQL查询引擎的作用, 它是将Spark SQL转换成RDD ...
- Python之logging.basicConfig函数各参数
filename: 指定日志文件名 filemode: 和file函数意义相同,指定日志文件的打开模式,'w'或'a' format: 指定输出的格式和内容,format可以输出很多有用信息,如上例所 ...
- jQuery格式化显示json数据
一.概述 JSONView 在gitlab上面,有一个jQuery JSONView插件,地址为:https://github.com/yesmeck/jquery-jsonview demo地址:h ...
- python_封装redis_list方法
xshell 进入 虚拟环境 安装 redis workon py3env # 进入虚拟环境 pip install redis # 安装redis deactivate # 退出虚拟环境 简单的封装 ...
- 详解java动态代理机制以及使用场景
详解java动态代理机制以及使用场景 https://blog.csdn.net/u011784767/article/details/78281384 深入理解java动态代理的实现机制 https ...