[poj 1201]Intervals 差分约束

POJ1201-Intervals 北大POJ1201-Intervals 解题报告+AC代码 立即下载

题目:http://poj.org/problem?id=1201

Intervals
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 24502 Accepted: 9317

Description

You are given n closed, integer intervals [ai, bi] and n integers c1, …, cn.
Write a program that:
reads the number of intervals, their end points and integers c1, …, cn from the standard input,
computes the minimal size of a set Z of integers which has at least ci common elements with interval [ai, bi], for each i=1,2,…,n,
writes the answer to the standard output.

Input

The first line of the input contains an integer n (1 <= n <= 50000) – the number of intervals. The following n lines describe the intervals. The (i+1)-th line of the input contains three integers ai, bi and ci separated by single spaces and such that 0 <= ai <= bi <= 50000 and 1 <= ci <= bi - ai+1.

Output

The output contains exactly one integer equal to the minimal size of set Z sharing at least ci elements with interval [ai, bi], for each i=1,2,…,n.

Sample Input
5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1

Sample Output
6

题意:要求满足bi-ai选数>=ci 中最小的集合;

思路:
如题:s[n]代表前n中选最小的集合,可得:

    s[bi]-s[ai-1]>=ci;(题)
    s[I+1]-s[I]>=0;(本身)
    s[I+1]-s[I]<=1;-->s[l]-s[I+1]>=-1(本身)

用最小值建边spfa求maxn-minn的最长路即可;

代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int head[60005],val[160005];
int tot,to[160005],nex[160005];
int n;
int aa,bb,cc;
queue<int> q;
int d[60005];
int vis[60005];
void spfa(int x)
{
    memset(d,-1,sizeof(d));
    d[x]=0;
    vis[x]=1;
    q.push(x);

    while(!q.empty())
    {
        int now=q.front();
        q.pop();
        vis[now]=0;

        for(int i=head[now];i!=-1;i=nex[i])
        {
            int v=to[i];
            if(d[v]==-1||d[v]<d[now]+val[i])
            {

                d[v]=d[now]+val[i];

                if(!vis[v])
                {
                    vis[v]=1;
                    q.push(v);
                } 
            }
        }
    }
}
void add(int x,int y,int v)
{
    int tmp=head[x];
    head[x]=++tot;
    nex[tot]=tmp;
    to[tot]=y;
    val[tot]=v; 
} 

int main()
{
    scanf("%d",&n);
    int minn=10000000;
    int maxn=-10000000;
    memset(head,-1,sizeof(head));
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&aa,&bb,&cc);
        aa--;
        add(bb,aa,cc);
        minn=min(aa,minn);
        maxn=max(maxn,bb);
    }
    for(int i=minn;i<maxn;i++)
    {
        add(i+1,i,0);
        add(i,i+1,-1);
    }
    spfa(maxn);
    printf("%d\n",d[minn]);

}
如何用Arduino和HX711压力传感器制作一个简易电子秤(含OLED显示) 本文详细介绍了如何使用Arduino、HX711压力传感器和OLED显示屏制作一个简易电子秤。从硬件连接到软件编程,提供了分步教程,包括核心元件功能解析、接线方法、库安装、模块测试以及关键的校准流程。项目实践性强,适合创客和DIY爱好者学习嵌入式系统与传感器应用。 阅读详情

相关推荐

Unity简单操作:PostProcessing的使用

Postprocessing是一个unity2018版本的集成后期插件,有了这个插件,之后用unity开发时,后期调整颜色、光晕等会很方便。 目录 新建一个postprocessing profile(配置文件)。​ 参数说明: 新建一个postprocessing profile(配置文件)。 在主相机下加一个组件PostProcess Layer。 注意:需要将相机的Layer层设置与Post Process Layer 下的Volume blending(体积混合)...

weixin_39114763的博客 7369

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

【POJ 1201】 Intervals(差分约束系统) 1716的升级版 把原本固定的边权改为不固定。 Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 23817   Accepted: 9023 Description You

ACMer' 2503

ROS新手必看:如何用URDF快速搭建UR5机械臂模型(附完整代码)

本文为ROS新手提供了一份详细的UR5机械臂URDF建模实战指南。通过解析URDF核心概念,逐步讲解如何定义link与joint,并整合官方网格文件,最终构建出完整的、可在RViz中可视化与控制的UR5模型。文章还介绍了模型验证、调试技巧以及如何添加碰撞与惯性属性,为后续的物理仿真与算法开发奠定坚实基础。

pz89012345的博客 498

POJ 1201 Intervals [差分约束系统]

Intervals Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %lluDescription You are given n closed, integer intervals [ai, bi] and n integers c1, …, cn. Write a program th

C'est la vie. 412

神经元细胞结构刨析(持续更新)

神经细胞的学习笔记

weixin_46596227的博客 2221

实战封神!YOLOv7 轻量化部署全攻略:ONNX格式转换+TensorRT极致加速(速度直接提升3-5倍,精度无损)

部署核心链路,这是YOLO系列部署的最优解,速度提升3~5倍,精度无损;ONNX是桥梁:解决模型兼容性问题,简化后能去掉冗余节点,是TensorRT加速的前提;TensorRT是核心:NVIDIA显卡的极致加速引擎,FP16量化是速度与精度的最优平衡,无需手动配置,一键开启;轻量化终极组合YOLOv7-tiny + 416尺寸 + TensorRT FP16,速度提升5~8倍,满足所有实时检测场景;避坑核心:转换参数必加,推理尺寸必须一致,engine文件显卡专属。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 308

POJ.1201 Intervals(区间约束)

POJ.1201 Intervals(区间约束) 思路:区间约束问题,转最长路跑spfaspfaspfa,注意区间是[0,50000][0,50000][0,50000]。但是我们连边是add(u−1,v,w)add(u-1,v,w)add(u−1,v,w),所以考虑整体右移一位,然后从000开始跑,此外还有一个限制是: d[v]−d[v−1]∈[0,1]d[v]-d[v-1]\in[0,1]d[v]−d[v−1]∈[0,1]。 再每次构建两条边即可。 #include<iostream> #i

Harris-H的博客 505

手把手教你学PCIE--固件与BIOS配置 - BIOS设置对PCIe性能的影响

本文详细分析了BIOS设置对PCIe性能的影响,并提供了优化建议。通过合理调整链路参数、功耗管理策略和高级功能配置,可以显著提升系统的性能和稳定性。本文将进一步分析BIOS设置如何影响PCIe设备的性能,并提供优化建议。BIOS(或UEFI)是系统启动时的第一个控制层,其设置直接决定了PCIe设备的工作状态和性能表现。BIOS中的功耗管理选项(如C-States、P-States)会影响PCIe链路的低功耗模式(L0s/L1)。MSI/MSI-X中断具有更高的性能和更好的可扩展性,应作为首选方案。

MHD0815的博客 996

poj 1201- Intervals (求最大路径)

Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end points and integers c1, ..., cn from the st...

Insistor 281

基于POD和神经网络的多工况温度场重构反演系统

本文提出了一种基于本征正交分解(POD)和神经网络的多工况温度场重构反演系统。该系统通过POD方法从多工况温度场数据中提取主要特征模态,构建神经网络模型建立工况参数与POD模态系数的映射关系,实现温度场的快速重构。系统采用Python实现,包含数据预处理、POD分解、神经网络训练和温度场重构等模块。实验结果表明,该方法能够有效降低计算复杂度,实现高精度的温度场预测。

huanghm88的专栏 277

Allegro172版本如何在联机模式下使用skill文件操作指导

注意:如果下次重新开启Symphony模式的时候可能导致symphony_skill中的文件内容被清空,所以最好将自己常用的skill文件都写到symphony_skill.txt中去,然后做好备份,需要的时候,在开启软件后把文件放到env目录中去。在用Allegeo172版本进行PCB设计的时候,有时会用到Symphony模式进行多人实时在线协同设计,如下图。这个模式设计起来可以提升设计速度,但是也有一个缺陷,就是不能使用skill文件。如下图,当调用skill的时候就会出现如下报错。

weixin_54787054的博客 1586

区间选点问题

1. 问题描述: Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end points and integers c1, ..., cn f...

二哈 1019

玩转Docker小游戏项目系列: Docker部署中国象棋网页小游戏

玩转Docker小游戏项目系列: Docker部署中国象棋网页小游戏

jks212454的博客 440

poj1201Intervals——差分约束系统

poj1201Intervals:http://poj.org/problem?id=1201 Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24036   Accepted: 9125 Description You are g

hahaAll的博客 457

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

POJ 1201 Intervals(差分约束)

POJ 1201 Intervals(差分约束) You are given n closed, integer intervals [ai, bi] and n integers c1, …, cn. Write a program that: reads the number of intervals, their end points and integers c1, …, cn ...

little_starfish的博客 257

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

POJ 1201 Intervals (差分约束系统, 贪心+线段树)

题目类型  Dijkstra算法的运用 题目意思 中文题目描述 解题方法 先枚举地位的范围(因为第1件物品必须在交易中出现所以范围区间的左端点就是 L1-m -> L1 右端点范围是 L1 -> L1+m) 确定范围后就是类似Dijkstra算法的贪心过程 d[i] 表示交易终点停在第 i 个物品时总共所需的花费 那么每次取最小的 d[i]

yunyouxi0's blog 1130

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

POJ1201 Intervals 差分约束

一、内容 You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end points and integers c1, ..., cn from the standard inp...

Tizzi的博客 1115

poj1201 Intervals——差分约束

题目:http://poj.org/problem?id=1201 差分约束裸题; 设 s[i] 表示到 i 选了数的个数前缀和; 根据题意,可以建立以下三个限制关系: s[bi] >= s[ai-1] + ci ( 1 <= i <= n) s[i] >= s[i-1] + 0 ( 1 <= i <= mx) s[i-1] >= s...

aodan5477的博客 165

POJ 1201 Intervals【差分约束】

POJ 1201 Intervalshttp://poj.org/problem?id=1201问题概述: 提供n组ai,bi,ci,表示在区间[ai,bi]中最少的整数个数,求所有提供区间中所包含的最小整数个数转化: 用S[i]表示[0,i]区间内的整数个数,则 1.S[bi+1]-S[ai]>=ci 2.1>=S[i+1]-S[i]&...

a48634331的博客 124

POJ1201-Intervals【差分约束,负环,SPFA】

正题 题目链接:http://poj.org/problem?id=1201 题目大意 求一个最少数量的数字集合满足 在li∼ril_i\sim r_ili​∼ri​的范围的数字至少是cic_ici​个 解题思路 设sis_isi​表示0∼i0\sim i0∼i的范围内数字个数。然后其实条件就是sr−si≥cs_r-s_i\geq csr​−si​≥c。然后就是差分约束。 但是需要注意si−s...

QuantAsk 511

【POJ1201】Intervals【差分约束】

差分约束好题,十分锻炼思维

stoorz 354

POJ 1201-Intervals(差分约束系统)

题目地址:POJ 1201 题意:构造一个集合,这个集合内的数字满足所给的n个条件,每个条件都是指在[a,b]内至少有c个数在集合内。问集合最少包含多少个点。即求至少有多少个元素在区间[a,b]内。 思路: 对于题目中所说的每个条件[a,b]内至少有c个数在集合可以表示为dis(b+1)-dis(a)>=c,可以看出是求最长路 然后题目中存在着隐藏条件。dis表示的是在[0,i-1]的范围

Rocky0429 1891

poj 1201 Intervals 差分约束

题目链接:poj 1201         给定每个范围内取数

飞火扑蛾的专栏 478

Intervals POJ - 1201 差分约束

Intervals POJ - 1201 差分约束 You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their e...

loooooog的博客 199

POJ 1201 Intervals 差分约束

是上一个 POJ 1716的加强版,上一个是每个区间至少有两个,这个是对于第i个区间,至少有ci个 给你n个区间,n 每个区间有左右两个端点,a,b,a,b 然后要你选一个点集,使这个点集在第i个区间中,至少有ci个个点,求这个点集的点的个数的最小值 做法还是贪心或者差分约束系 但是贪心要优化一下 先说差分约束吧 dist[i]表示[0,i)中包含的数的个数 dist[

一蓑烟雨任平生 395

POJ 1201 Intervals(差分约束)

Intervals 题意:给n个区间,一个集合Z,对于第i个区间[a, b],集合Z与区间[a,b]的交集元素个数大于等于cic_ici​。已知n个区间以及c,问你集合Z的大小最小是多少? 思路: 特征:最小值、不等式 所以我们尝试差分约束的思想,写不等式 差分约束 差分约束是解决这样一类问题 给出n个形如x[j]−x[i] <= k的式子,求x[n]−x[1]的最大/最小值 观察题目,...

weixin_44412226的博客 213
上一篇: [poj 3342]Party at Hali-Bula 树形dp
下一篇: 【poj 2983】Is the Information Reliable? 差分约束
ALPS233
博客等级 码龄11年 25粉丝 191原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值