【题目链接】

点击打开链接

【算法】

令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. thinkphp5 框架修改的地方

    框架修改的地方 vendor/topthink/think-captcha/src/Captcha.php api验证码入库 196行 $img_code = strtoupper(implode(' ...

  2. linux文件及目录的权限管理

    一.文件的权限 1.文件权限的查看 命令:ls -l 可以使用ll命令代替 ls -l 2.ls -l 所包含的信息 (1)权限信息 (-rw-r--r-- ) 一共有10位 a.第一位:表示文件信息 ...

  3. LIBSVM使用方法及参数设置

    LIBSVM 数据格式需要---------------------- 决策属性 条件属性a 条件属性b ... 2 1:7 2:5 ... 1 1:4 2:2 ... 数据格式转换--------- ...

  4. Linux学习总结(22)——CentOS7.2安装Nginx

    一.使用Yum安装(推荐) 使用Yum安装是推荐的方式,整体的流程非常的简单,也不容易出错,如果不需要什么特殊配置,建议使用Yum尽进行安装. 1.安装epel-release源并进行安装 1 2 3 ...

  5. 使用JS对form的内容验证失败后阻止提交

    1.form的两个事件 submit,提交表单,如果直接调用该函数,则直接提交表单 onSubmit,提交按钮点击时先触发,然后触发submit事件.如果不加控制的话,默认返回true,因此表单总能提 ...

  6. linux & command line & console & logs

    linux & command line & console & logs how to get the logs form linux command console htt ...

  7. 自己打断点走的struts流程&拦截器工作原理

    ①. 请求发送给 StrutsPrepareAndExecuteFilter ②. StrutsPrepareAndExecuteFilter 判定该请求是否是一个 Struts2 请 求(Actio ...

  8. HDU.P1100 Trees Made to Order 解题报告

    http://www.cnblogs.com/keam37/p/3637717.html  keam所有 转载请注明出处 Problem Description We can number binar ...

  9. cogs——1364. 聚会

    1364. 聚会 ★   输入文件:partyb.in   输出文件:partyb.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 小S想要从某地出发去同学k的家中参加 ...

  10. 06-js的逻辑结构

    <html> <head> <title>js的逻辑结构和循环结构学习</title> <meta charset="UTF-8&quo ...