[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]);

}
网站进行企业微信授权登录(附带代码超详细版) 企业微信的扫码登录官方文档 https://work.weixin.qq.com/api/doc/90000/90135/90988 企业微信扫码登录认证流程 上面是官方的图片,看上去比较复杂。因此我用直白简洁的语言梳理下流程。 1、首先在自己的网站上获取到企业微信登录的二维码(二维码怎么获取稍后再说,这里想象下你已经有了一个二维码) 2、你拿着手机扫描二维码,确认登录之后,页面就会自己进行重定向的跳转,跳转的url如何配置下面再讲,但是注意,这个重定向的url可以是内网地址 3、重定向到指 阅读详情

相关推荐

解决Cursor AI工具地域限制报错的方法与原理

地理围栏(GEO-fencing)是现代云服务常用的访问控制技术,通过IP地址库匹配、支付系统验证等方式实现区域限制。在AI编程工具领域,这种技术常导致类似Cursor出现的'unsupported country region'报错。从技术实现看,服务商会综合HTTP头信息、时区设置等多维度数据进行地理位置判断。开发者可通过调整网络出口、配置本地模型或使用企业版等方案解决。本文以Cursor为例,详细分析了AI工具地域限制的底层原理,并提供了包括Ollama本地部署在内的多种工程实践方案,特别适合需要稳定

weixin_30820077的博客 1112

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

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

ACMer' 2504

HX720/HX711 数据采集实战:从硬件配置到姿态解析(附源码详解)

本文详细解析了HX720/HX711数据采集传感器的硬件配置与姿态解析实战技巧,包括选型指南、电路设计避坑、抗干扰方案及源码实现。通过优化驱动代码和数据处理算法,提升采样率与精度,适用于动态称重和工业检测等场景。附源码详解,助力开发者快速掌握高精度数据采集技术。

weixin_30752699的博客 665

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

12V电源电路五层防护设计实战指南

12V电源电路是工业控制、车载电子和智能终端中最基础的供电架构,其可靠性不取决于稳压精度,而取决于对反接、浪涌、短路、过温等典型故障的响应能力。理解TVS钳位原理、P-MOSFET防反接机制及eFuse可编程限流逻辑,是构建鲁棒电源系统的核心。技术价值在于将保护从‘事后补救’升级为‘事前拦截’,显著提升产品MTBF并降低售后返修率。典型应用场景涵盖PLC辅助电源、ADAS摄像头供电、IoT网关主板等严苛环境设备。本文聚焦12V输入端到负载输出端的五层串行防护链设计,深度融合TVS选型、MOSFET导通阈值与

weixin_30983965的博客 307

Materials studio中的简单聚合物的建立及盒子的弛豫

涉及模块 Amorphous Cell-construction Forcite-caculation Build Polymers-Homopolymer

快乐学术猿 3万+

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

解决anaconda占用C盘空间过多问题

anaconda就算安装在其他盘,默认会把索引、锁定文件、压缩包等都放到系统盘(C盘),我用了两年,占用30GB。 1. 卸载不用的虚拟环境 查看已安装的虚拟环境 conda env list 卸载不用的、过期的虚拟环境 conda remove -n (要卸载的环境的名字) --all 2. 删除索引缓存、锁定文件、未使用过的包和tar包 conda clean -a 清理完之后,删除了15GB,还剩15GB,舒服了 ...

沉迷单车的追风少年 3万+

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

机器翻译的评价标准:BLEU、ROUGE等指标说明及代码实现

机器翻译领域常用的自动评价指标主要包括BLEU、ROUGE、METEOR和COMET四大类。BLEU基于n-gram精确率和短句惩罚,ROUGE关注召回率,METEOR结合精确率和召回率并考虑同义词,COMET则利用预训练模型计算语义相似度。这些指标各有特点:BLEU适用于机器翻译,ROUGE对长句友好,METEOR更接近人工评分,COMET无需参考译文。代码实现上,sacrebleu、rouge-score等库提供了便捷的计算方式。新兴趋势包括基于BERT等模型的语义评估和大语言模型评估器,但传统指标仍占

数据知道的博客 9425

高通camx进程ExtensionModule::TeardownOverrideSession类型crash问题分析之一:【死锁导致】

摘要:本文分析了一个在相机老化测试中出现的pthread_cond_wait持锁超时导致的ExtensionModule::TeardownOverrideSession崩溃问题。通过crash堆栈和日志分析,发现close阶段存在近1分钟的无响应期。进一步分析trace文件发现存在多线程死锁:ChiFeature2Graph::GenerateSmartErrorCode和ChiFeature2RequestObject::SetCurRequestState两个线程分别持有不同锁并互相等待对方释放。最终

1115

区间选点问题

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

2024 年 9 月青少年软编等考 C 语言三级真题解析

2024 年 9 月青少年软编等考 C 语言三级真题解析。

发布少儿编程考级的真题和优秀竞赛题解析,以及一些讲义。 1744

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的博客 459

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

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的博客 258

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

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

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

yunyouxi0's blog 1130

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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的博客 125

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 514

【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 1893

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、付费专栏及课程。

余额充值