【题目链接】

点击打开链接

【算法】

令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的更多相关文章

  1. 【POJ 1201】 Intervals(差分约束系统)

    [POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS   Memory Limit: ...

  2. 【38.24%】【POJ 1201】Intervals

    Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25902 Accepted: 9905 Description You are ...

  3. 【POJ 1716】Integer Intervals(差分约束系统)

    id=1716">[POJ 1716]Integer Intervals(差分约束系统) Integer Intervals Time Limit: 1000MS   Memory L ...

  4. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  5. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  6. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  7. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  8. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  9. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

随机推荐

  1. [Python3网络爬虫开发实战] 3.1-使用urllib

    在Python 2中,有urllib和urllib2两个库来实现请求的发送.而在Python 3中,已经不存在urllib2这个库了,统一为urllib,其官方文档链接为:https://docs.p ...

  2. 微信小程序 video组件----真机测试position:fixed无效 且有黑底

    1.问题描述 video组件fixed后,视频随页面滚动,且有个黑色底停留在页面. 页面滚动前 滚动后 这里贴一下修改前代码,在微信开发者工具看是没有任何问题的.在手机端测试就有以上的问题 <v ...

  3. 8.url路由

    1.单一路由对应 url(r'^index/$', views.index), 这里要注意的是,/$ 表示只有只/结尾的才有效,如果把$符号去掉的话,只要是以index/开头都会匹配到这个url. 2 ...

  4. Spider-Python爬虫之使用Selenium模拟浏览器行为

    分析 他的代码比较简单,主要有以下的步骤:使用BeautifulSoup库,打开百度贴吧的首页地址,再解析得到id为new_list标签底下的img标签,最后将img标签的图片保存下来. header ...

  5. Spring Boot 2 (二):Spring Boot 2 尝鲜-动态 Banner

    Spring Boot 2.0 提供了很多新特性,其中就有一个小彩蛋:动态 Banner,今天我们就先拿这个来尝尝鲜. 配置依赖 使用 Spring Boot 2.0 首先需要将项目依赖包替换为刚刚发 ...

  6. UVaLive 4868 Palindrometer (暴力 / 构造)

    题意: 给定一个固定长度的字符串, 字符串是一个含有前导0的数字, 问这个数字加上多少能构成一个回文字符串. 分析: 其实这题有很多种方法, 方法12是我做完后看别人代码总结的, 方法3是我当时想的一 ...

  7. UVA 1596 Bug Hunt (大模拟 栈)

    题意: 输入并模拟执行一段程序,输出第一个bug所在的行. 每行程序有两种可能: 数组定义: 格式为arr[size]. 例如a[10]或者b[5],可用下标分别是0-9和0-4.定义之后所有元素均为 ...

  8. Python接口测试之unittest框架(五)

    Test-driven development(TDD)开发模式在今天已经不是什么新奇的事了,它的开发思维是在开发一个产品功能的时候,先 编写好该功能的测试代码,在编写开发比如,比如要写二个数相除的函 ...

  9. hdu 3038带权并查集

    #include<stdio.h> #include<string.h> #define N  200100 struct node { int x,count; }pre[N ...

  10. zoj4710暴力

    #include<stdio.h> #include<string.h> #define N 110 int map[N][N]; int main() { int n,m,k ...