【POJ 1201】 Intervals
【题目链接】
【算法】
令sum(n)表示区间[1,n]中选了几个点
那么,显然有以下不等式 :
1. sum(n)- sum(n - 1) >= 0
2. sum(n) - sum(n - 1) <= 1
3. sum(bi) - sum(ai-1) >= ci
那么,差分约束系统是可以解决这个问题的(SPFA最长路)
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 50001
const int INF = 2e9; struct Edge
{
int to,w,nxt;
} e[MAXN<<]; int i,n,tot,a,b,c;
int dis[MAXN+],head[MAXN+];
bool inq[MAXN+]; inline void add(int u,int v,int w)
{
tot++;
e[tot] = (Edge){v,w,head[u]};
head[u] = tot;
} inline void spfa(int s)
{
int i,cur,v;
queue< int > q;
q.push(s);
dis[s] = ;
for (i = ; i <= MAXN; i++) dis[i] = -INF;
inq[s] = true;
while (!q.empty())
{
cur = q.front();
q.pop();
inq[cur] = false;
for (i = head[cur]; i; i = e[i].nxt)
{
v = e[i].to;
if (dis[cur] + e[i].w > dis[v])
{
dis[v] = dis[cur] + e[i].w;
if (!inq[v])
{
inq[v] = true;
q.push(v);
}
}
}
}
} int main()
{ scanf("%d",&n);
for (i = ; i < MAXN; i++) add(i,i+,);
for (i = MAXN; i > ; i--) add(i,i-,-);
for (i = ; i <= n; i++)
{
scanf("%d%d%d",&a,&b,&c);
add(a,b+,c);
}
spfa();
printf("%d\n",dis[MAXN]); return ; }
【POJ 1201】 Intervals的更多相关文章
- 【POJ 1201】 Intervals(差分约束系统)
[POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS Memory Limit: ...
- 【38.24%】【POJ 1201】Intervals
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25902 Accepted: 9905 Description You are ...
- 【POJ 1716】Integer Intervals(差分约束系统)
id=1716">[POJ 1716]Integer Intervals(差分约束系统) Integer Intervals Time Limit: 1000MS Memory L ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
随机推荐
- 17Spring前置通知
1).加入jar包:下载地址 spring-beans-4.1.6.RELEASE.jar commons-logging-1.1.3.jar spring-context-4.1.6.RELEASE ...
- Python Pandas库的学习(一)
今天我们来学习一下Pandas库,前面我们讲了Numpy库的学习 接下来我们学习一下比较重要的库Pandas库,这个库比Numpy库还重要 Pandas库是在Numpy库上进行了封装,相当于高级Num ...
- JS 去除字符串空格
$.trim()是jQuery提供的函数,用于去掉字符串首尾的空白字符. "abc 123 def".replace(/\s/g, "") 去除所有的空格
- Python接口测试之unittest框架(五)
Test-driven development(TDD)开发模式在今天已经不是什么新奇的事了,它的开发思维是在开发一个产品功能的时候,先 编写好该功能的测试代码,在编写开发比如,比如要写二个数相除的函 ...
- LaTex/Overleaf使用笔记
1. 添加网页引用 @misc{ r1, author = "Wikipedia", title = "Binary decision diagram --- { ...
- HDU 4944
FSF’s game Problem Description FSF has programmed a game.In this game, players need to divide a rect ...
- java中文乱码问题的处理方式
URL访问java时. 注意: URL: 编码二次 URLEncoder.encode(URLEncoder.encode(searchKey, "utf-8"),"ut ...
- JSP的异常处理
以下内容引用自http://wiki.jikexueyuan.com/project/jsp/exception-handling.html: 当写JSP代码的时候,有可能会留下一个编码错误,并且它会 ...
- Centos6.4安装Zimbra初步教程
环境: 1.centos6.4*64位版本 2.主机最好内存设置在2G以上,要不安装的时候卡死你 3.下载最新的开源的Zimbra安装包,下载zcs-8.0.4_GA_5737.RHEL6_64.20 ...
- Telnet登入cisco router 1800
Login to Router and change to privileged modec:\>telnet 192.168.6.1Trying 192.168.6.1...Connected ...