给定ai,bi, ci 表示区间[ai,bi]内至少有ci个点, 要求对于所有给定的ai,bi,ci,  至少多少个点才能满足题目的条件

重做这一题学到的一点是, 可以设变量来表示一些东西,然后才能找出约束的条件,  s[i]表示区间0到i内有多少个点,  那么s[bi] - s[ai-1] >= ci 就是约束的条件

当然了,也有隐藏的条件  1>= s[i] - s[i-1] >=0

可以用最长路来求这一题,最短路当然也是可以的。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
using namespace std;
const int INF = <<;
const int N = + ;
struct Node
{
int to, dist, next;
bool operator<(const Node&rhs)const
{
return dist < rhs.dist;
}
}g[N];
int head[N], e;
int dist[N];
void addEdge(int a, int b, int c)
{
g[e].to = b;
g[e].dist = c;
g[e].next = head[a];
head[a] = e++;
}
int dij(int x, int y)
{
priority_queue<Node> q;
for (int i = x; i <= y; ++i)
dist[i] = -INF;
Node cur, tmp;
dist[x] = cur.dist = ;
cur.to = x;
q.push(cur);
while (!q.empty())
{
cur = q.top(); q.pop();
int u = cur.to;
if (dist[u] > cur.dist)
continue;
for (int i = head[u]; i != -; i = g[i].next)
{
int v = g[i].to;
if (dist[v] < dist[u] + g[i].dist)
{
tmp.dist = dist[v] = dist[u] + g[i].dist;
tmp.to = v;
q.push(tmp);
}
}
}
return dist[y];
}
int main()
{
int n, Min, Max, a, b, c;
Node tmp;
while (scanf("%d", &n) != EOF)
{
e = ;
memset(head, -, sizeof(head));
Min = INF, Max = -INF;
for (int i = ; i <= n; ++i)
{
scanf("%d%d%d", &a, &b, &c);
a++;
b++;
Min = min(a - , Min);
Max = max(b, Max);
addEdge(a - , b, c);
}
for (int i = Min+; i <= Max; ++i)
{
addEdge(i - , i, );
addEdge(i, i - , -); }
printf("%d\n", dij(Min, Max));
}
return ;
}

POJ1201 差分约束的更多相关文章

  1. POJ1201 Intervals 【差分约束】

    题目链接 POJ1201 题解 差分约束 令\(a[i]\)表示是否选择\(i\),\(s[i]\)表示\(a[i]\)的前缀和 对\(s[i] \quad i \in [-1,50000]\)分别建 ...

  2. POJ1201 Intervals(差分约束)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 10966 Description You ...

  3. POJ1201:Intervals(差分约束)

    差分约束经典题.设s[i]为前缀和,则有 s[i]-s[i-1]<=1 (i往i-1连-1的边) s[i]>=s[i-1] (i-1往i连0的边) s[b]-s[a-1]>=c (a ...

  4. POJ1201 Intervals (差分约束)

    You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: ...

  5. POJ1201:Intervals【差分约束】

    题目大意:给出N个闭区间,每个区间给出一个ci值,让你找出最小的数集Z使得每个闭区间都有不少于ci个Z中的元素,求card(Z) 思路:06年集训队论文<浅析差分约束系统>有详细的解题,设 ...

  6. poj1201 Intervals——差分约束

    题目:http://poj.org/problem?id=1201 差分约束裸题: 设 s[i] 表示到 i 选了数的个数前缀和: 根据题意,可以建立以下三个限制关系: s[bi] >= s[a ...

  7. POJ1201基础差分约束

    题意:       有一条直线,直线上做多有50000个点,然后给你组关系 a b c表明a-b之间最少有c个点,问直线上最少多少个点. 思路:        a-b最少有c个点可以想象a到b+1的距 ...

  8. Intervals(差分约束)

    http://poj.org/problem?id=1201 题意:给出N个整数区间[ai,bi],并且给出一个约束ci,( 1<= ci <= bi-ai+1),使得数组Z在区间[ai, ...

  9. K - Candies(最短路+差分约束)

    题目大意:给N个小屁孩分糖果,每个小屁孩都有一个期望,比如A最多比B多C个,再多了就不行了,会打架的,求N最多比1多几块糖 分析:就是求一个极小极大值...试试看 这里需要用到一个查分约束的东西 下面 ...

随机推荐

  1. LeetCode--Best Time to Buy and Sell Stock (贪心策略 or 动态规划)

    Best Time to Buy and Sell Stock Total Accepted: 14044 Total Submissions: 45572My Submissions Say you ...

  2. Trufun云端建模平台之云端UML工具发布

    Trufun云端建模平台包括云端UML工具,云端BPMN工具,云端思维导图工具. 云端UML工具是目前最先进的基于HTML5的UML2.x建模工具,所有代码基于JAVA开发,支持类图.用例图.活动图. ...

  3. 【Dev Club 分享】腾讯验证码的十二年

    源:http://mp.weixin.qq.com/s?__biz=MzA3NTYzODYzMg==&mid=2653578147&idx=3&sn=94a8f8f8b4a23 ...

  4. js获取上传文件的绝对路径

    在html中    <input type="file" id="importFile" />    <input type="bu ...

  5. 王立平--android中的anim(动画)

    简单有用步骤: 1.新建anim目录. 2.在anim下新建xml文件, 3.在xml下编写自己须要动画. 简单样例: 给Imageview加入动画 public class MainActivity ...

  6. Note:This element neither has attached source nor attached Javadoc

    在用Eclipse编写程序时,发现把鼠标放到类名上时出现标题的提示 解决方法: 右击项目,选择 properties –> Java Build Path –> Libraries,如图 ...

  7. The mmap module

    The mmap module The mmap module (New in 2.0) This module provides an interface to the operating syst ...

  8. 实现Runnable接口和扩展Thread使用场景

    在上篇博文:java学习笔记-Thread中我们知道创建子线程的两个方式:实现Runnable接口和扩展Thread. 扩展Thread类和实现Runnable接口的使用场景: Thread类定义了派 ...

  9. 实现ios常见菜单效果的思路

    眼下见过的实现边側菜单的效果.比較流行的有下面三种:(效果图) 1.菜单条覆盖在部分主视图上 附上实现该效果的一个不错的源代码地址: http://code4app.com/ios/RNFrosted ...

  10. libevent book——event | Gaccob的博客

    libevent book——event | Gaccob的博客 libevent book——event 发表于 2013 年 2 月 22 日 由 gaccob 原文地址:http://www.w ...