传送门

分析

我们设S[i]表示到第i个数为止一共有多少个数在集合Z之中,最终答案就是S[max]-S[min]的最小值。所以我们不难发现对于每一个[ai,bi]都表示S[bi]-S[ai-1]>=ci,而我们又知道0<=S[i]-S[i-1]<=1,所以建图策略便是每一个ai向bi连一条权值为ci的边,i-1向i连一条权值为0的边,i向i-1连一条权值为-1的边,然后跑最长路就可以了。注意在代码中为了方便起见所有的值i向后移了一位。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int inf = 0x3f3f3f3f;
vector<pair<int,int> >v[];
int d[],iq[];
queue<int>q;
inline void spfa(int s){
memset(d,-,sizeof(d));
memset(iq,,sizeof(iq));
q.push(s);d[s]=;iq[s]=;
while(!q.empty()){
int x=q.front();
q.pop();iq[x]=;
for(int i=;i<v[x].size();i++){
int y=v[x][i].first,z=v[x][i].second;
if(d[y]<d[x]+z){
d[y]=d[x]+z;
if(!iq[y]){
q.push(y);
iq[y]=;
}
}
}
}
return;
}
int main(){
int n,m,i,j,k,s=inf,t=-;
scanf("%d",&n);
for(i=;i<=n;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
y++;
v[x].push_back(make_pair(y,z));
s=min(s,x),t=max(t,y);
}
for(i=s;i<t;i++){
v[i].push_back(make_pair(i+,));
v[i+].push_back(make_pair(i,-));
}
spfa(s);
printf("%d\n",d[t]);
return ;
}

loj10087 Intervals的更多相关文章

  1. [LeetCode] Non-overlapping Intervals 非重叠区间

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  2. [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  3. [LeetCode] Merge Intervals 合并区间

    Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...

  4. POJ1201 Intervals[差分约束系统]

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26028   Accepted: 9952 Descri ...

  5. Understanding Binomial Confidence Intervals 二项分布的置信区间

    Source: Sigma Zone, by Philip Mayfield The Binomial Distribution is commonly used in statistics in a ...

  6. Leetcode Merge Intervals

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  7. LeetCode() Merge Intervals 还是有问题,留待,脑袋疼。

    感觉有一点进步了,但是思路还是不够犀利. /** * Definition for an interval. * struct Interval { * int start; * int end; * ...

  8. Merge Intervals 运行比较快

    class Solution { public: static bool cmp(Interval &a,Interval &b) { return a.start<b.star ...

  9. [LeetCode] 435 Non-overlapping Intervals

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

随机推荐

  1. python在字符串中查找字符

    两类函数: find(),rfind() index(),rindex() 找到了都返回下标. find找不到返回-1,index找不到抛出ValueError. 带r的表示从右向左找. 都可以使用第 ...

  2. (转)SPFA算法

    原文地址:http://www.cnblogs.com/scau20110726/archive/2012/11/18/2776124.html 粗略讲讲SPFA算法的原理,SPFA算法是1994年西 ...

  3. redis 双写一致性问题

    首先,缓存由于其高并发和高性能的特性,已经在项目中被广泛使用.在读取缓存方面,大家没啥疑问,都是按照下图的流程来进行业务操作. 但是在更新缓存方面,对于更新完数据库,是更新缓存呢,还是删除缓存.又或者 ...

  4. Http之ContentType

    引言: 在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值 ...

  5. mysql之 mysql数据库压力测试工具(mysqlslap)

    mysqlslap是从MySQL的5.1.4版开始就开始官方提供的压力测试工具.通过模拟多个并发客户端并发访问MySQL来执行压力测试,同时提供了较详细的SQL执行数据性能报告,并且能很好的对比多个存 ...

  6. 摘之知乎网友...PHYTIN学习

    作者:东瓜王链接:https://www.zhihu.com/question/19593179/answer/23746083来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  7. mybatis 学习四 (上)resutlMap

    SQL 映射XML 文件是所有sql语句放置的地方.需要定义一个workspace,一般定义为对应的接口类的路径.写好SQL语句映射文件后,需要在MyBAtis配置文件mappers标签中引用,例如: ...

  8. Celery-4.1 用户指南:Testing with Celery (用 Celery测试)

    任务与单元测试 在单元测试中测试任务行为的推荐方法是用mocking. Eager mode: task_always_eager 设置启用的 eager 模式不适用于单元测试. 当使用eager模式 ...

  9. Python函数(三)-局部变量

    全局变量 全局变量在函数中能直接访问 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" name = 'John' def te ...

  10. 在.net中使用redis(StackExchange.Redis)

    本文介绍如何在.net中使用redis 安装 代码使用 StackExchange.Redis基础使用 StackExchange.Redis中的事务 安装(windows平台) 安装Chocolat ...