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,按编号排成一排准备吃东西,有些牛的关系比较好,所以希望他们不超过一定的距离,也有一些牛的关系很不好,所以希望彼此之间要满足某个关系,牛可以 ...
随机推荐
- XT交易所API
HTTPAPI xt为用户提供了一个简单的而又强大的API,旨在帮助用户快速高效的将xt交易功能整合到自己应用当中. API地址域名地址 域名地址:https://www.xt.com/ 使用说明 使 ...
- 负载均衡Nginx和F5的区别
今早上看书,看到为了保证Zuul的高可用性,在Zuul的前端可以使用Nginx或F5再次进行负载转发 使用过Nginx,那F5是什么,他们有什么区别吗? (1)F5 F5负载均衡器是应用交付网络的全球 ...
- RSA非对称式加解密笔记
1.服务器生成[公钥]和[私钥],成对生成: 2.客户端生成证书信息,使用[公钥]进行加密,前提是有公钥,并生成证书信息: 3.客户端发送自身的计算机名.MAC.用户名.证书内容给服务器: 4.服务器 ...
- HBase 详解
1.HBase 架构 ============================================ 2. HBase Shell 操作 2.1. 基本操作 进入HBase客户端命令行:bi ...
- 20 SSM三大框架的整合
1.SSM整合的相关概念 (1)整合说明:SSM整合可以使用多种方式,优先使用XML + 注解的方式(2)整合的思路 1.先搭建整合的环境 2.先把Spring的配置搭建完成 3.再使用Spring整 ...
- 2019-7-19 包、logging模块、hashlib(加密模块)、openpyxl模块、深浅拷贝
一.包 什么是包: 它是一系列模块文件的结合体,表示形式就是一个文件夹.该文件内部通常会有一个__init__.py文件,包的本质还是一个模块,可以被调用,调包就相当于与调用__init__.py文件 ...
- 【LeetCode】 #7:反转整数 C语言
目录 题目 思路 初步想法 进一步想法 总结 最近打算练习写代码的能力,所以从简单题开始做. 大部分还是用C语言来解决. @(解法) 题目 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数 ...
- java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
请求的协议不对 解决方案: 把请求的https改成http
- DISPLAY FORMAT 語法
- NOI2019:Stay at Home
7.16 NOI D1 从同步赛开始更起好了 先看了一圈题目,发现T1非常可做,二次函数因为对称轴在\(x < 0\)的地方所以有跟一次函数类似的单调性,搞个单调队列维护一下似乎就可以了.大力码 ...