POJ 1201 && HDU 1384 Intervals(差动制动系统)
依据题目意思。能够列出不等式例如以下:
Sj-Si>=c;
Si-S(i-1)>=0;
S(i-1)-Si>=-1;
然后用最短路spfa来解决这个不等式。
用max来当源点,0为终点。
终于的-d[0]就是答案。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
const int INF=0x3f3f3f3f;
int d[60000], vis[60000], head[60000], cnt, q[5000000];
struct node
{
int u, v, w, next;
} edge[1000000];
void add(int u, int v, int w)
{
edge[cnt].v=v;
edge[cnt].w=w;
edge[cnt].next=head[u];
head[u]=cnt++;
}
void spfa(int s)
{
memset(d,INF,sizeof(d));
d[s]=0;
memset(vis,0,sizeof(vis));
int ss=0, ee=0;
q[ss++]=s;
while(ss>ee)
{
int u=q[ee++];
vis[u]=0;
for(int i=head[u]; i!=-1; i=edge[i].next)
{
int v=edge[i].v;
if(d[v]>d[u]+edge[i].w)
{
d[v]=d[u]+edge[i].w;
if(!vis[v])
{
vis[v]=1;
q[ss++]=v;
}
}
}
}
}
int main()
{
int a, b, c, n, i, max1, min1;
while(scanf("%d",&n)!=EOF)
{
memset(head,-1,sizeof(head));
max1=-1;
min1=INF;
cnt=0;
while(n--)
{
scanf("%d%d%d",&a,&b,&c);
if(max1<b)
max1=b;
if(min1>a)
min1=a;
add(b,a-1,-c);
}
for(i=1; i<=max1; i++)
{
add(i-1,i,1);
add(i,i-1,0);
}
spfa(max1);
printf("%d\n",-d[0]);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
POJ 1201 && HDU 1384 Intervals(差动制动系统)的更多相关文章
- hdu 1384 Intervals (差分约束)
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1384 Intervals(差分约束)
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1384 Intervals (差分约束)
Problem - 1384 好歹用了一天,也算是看懂了差分约束的原理,做出第一条查分约束了. 题意是告诉你一些区间中最少有多少元素,最少需要多少个元素才能满足所有要求. 构图的方法是,(a)-> ...
- hdu 1384 Intervals
差分约束系统. 求最小值,用最长路来解决. #include<cstdio> #include<cstring> #include<cmath> #include& ...
- HDU 1384 Intervals &洛谷[P1250]种树
差分约束 差分约束的裸题,关键在于如何建图 我们可以把题目中给出的区间端点作为图上的点,此处应注意,由于区间中被标记的点的个数满足区间加法,这里与前缀和类似,对于区间[L..R]来说,我们加入一条从L ...
- HDU 1384 Intervals【差分约束-SPFA】
类型:给出一些形如a−b<=k的不等式(或a−b>=k或a−b<k或a−b>k等),问是否有解[是否有负环]或求差的极值[最短/长路径].例子:b−a<=k1,c−b&l ...
- hdu 1384 Intervals (差分约束)
/* 给你 n 个区间 [Ai, Bi],要求从每一个区间中至少选出 Ci 个数出来组成一个序列 问:满足上面条件的序列的最短长度是多少? 则对于 不等式 f(b)-f(a)>=c,建立 一条 ...
- poj 1201 Intervals 解题报告
Intervals Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Submit Statu ...
- POJ 1384 Intervals (区间差分约束,根据不等式建图,然后跑spfa)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1384 Intervals Time Limit: 10000/5000 MS (Java/Others ...
随机推荐
- Android应用UI架构
这个标题听起来可能有点大.事实上这里主要就是讨论一个应用程序的UI组件,是全用Activity还是全用Fragment.或者是二者皆有.以及使用Activity和Fragment的一些注意事项. A ...
- error C2871: 'std' : does not exist or is not a namespace
#include <iostream.h> using namespace std; 然后编译时出现 error C2871: 'std' : does not exist or is n ...
- 折返(Reentrancy)VS线程安全(Thread safety)
在Wiki上,折返例如,下面的定义(接) In computing, a computer program or subroutine is called reentrant if it can be ...
- nginx+tomcat实现动静分离(转)
本文设计的动静分离结构 在本文中,我们将静态资源放在 A 主机的一个目录上,将动态程序放在 B 主机上,同时在 A 上安装 Nginx 并且在 B 上安装 Tomcat.配置 Nginx,当请求的是 ...
- error LNK2019: 解析的外部符号 __imp__DispatchMessageW@4,在函数的符号 _WinMain@16 据引述
错误: 1>WinMain.obj : error LNK2019: 解析的外部符号 __imp__DispatchMessageW@4,在函数的符号 _WinMain@16 据引述 1> ...
- 从源代码分析modelDriven拦截器和params拦截器和拦截器prepare 和paramsPrepareParamsStack拦截器栈(让你的Struts2代码更简洁——如何培养框架设计能力
源代码文件:Web App Libraries/struts2-core-2.3.15.3.jar/struts-default.xml 拦截器modelDriven: <interceptor ...
- SQLSERVER复制优化之一《减少包大小》
原文:SQLSERVER复制优化之一<减少包大小> SQLSERVER复制优化之一<减少包大小> 自从搭了复制之后以为可以安枕无忧了,谁不知问题接踵而来 这次遇到的问题是丢包, ...
- Unity3D游戏开发最佳实践20技能(两)
[扩展和MonoBehaviourBase] 21.扩展一个自己的Mono Behaviour基类.然后自己的全部组件都从它派生 这能够使你方便的实现一些通用函数.比如类型安全的Invoke.或者是一 ...
- 【核心研究】消息队列_MessageQueue
消息队列排队过程中的消息.这第一条消息将首先被处理.但假设消息本身指定要处理的时间.我们必须等待,直到时间的消息处理能力.新闻MessageQueue正在使用Message类的表示,队列中的邮件保存结 ...
- centos编译内核:no space left on device 解
1.问题:在下面的根文件夹中的原始源代码 编译出现 no space left on device 利用df -h 命令查看 根文件夹空间占用完成 2.将源代码改在其它空间非常足的地方编译 在make ...