Maximal Intersection Codeforces Round #506 Div. 3 贪心+暴力

博客围绕在数轴上给定n个区间,要求删除一个区间使剩余(n - 1)个区间交集长度最大的问题展开。介绍了区间交集的概念和计算方法,输入输出格式,还提到最初理解题意有误,解决思路是暴力枚举删除的区间并求剩余区间交集。

You are given nn segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.

The intersection of a sequence of segments is such a maximal set of points (not necesserily having integer coordinates) that each point lies within every segment from the sequence. If the resulting set isn't empty, then it always forms some continuous segment. The length of the intersection is the length of the resulting segment or 00 in case the intersection is an empty set.

For example, the intersection of segments [1;5] and [3;10] is [3;5] (length 2), the intersection of segments [1;5] and [5;7]is [5;5](length 0) and the intersection of segments [1;5] and [6;6] is an empty set (length 0).

Your task is to remove exactly one segment from the given sequence in such a way that the intersection of the remaining (n−1)(n−1)segments has the maximal possible length.

Input

The first line contains a single integer nn (2≤n≤3⋅10^5) — the number of segments in the sequence.

Each of the next nn lines contains two integers lili and riri (0≤li≤ri≤10^9) — the description of the ii-th segment.

Output

Print a single integer — the maximal possible length of the intersection of (n−1) remaining segments after you remove exactly one segment from the sequence

把题意弄错了,想了好久……

题意删除一段区间,使得剩下的区间都相交的部分最大;

假设现在不删区间,所有区间都相交的部分长度一定是 R_{min}-L_{max} ;  L,R分别表示区间左右端点;

现在要删去一个,直接暴力枚举删哪个区间即可,剩下的区间求R_{min}-L_{max}

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long LL;
const int MOD=1e9+7;
const int maxn=1e5+7;
multiset<int> l,r;
vector<pair<int,int> > v;
int main()
{
    int n;
    scanf("%d",&n);
    int L,R;
    for(int i=0;i<n;++i)
    {
        scanf("%d%d",&L,&R);
        v.push_back(make_pair(L,R));
        l.insert(L);
        r.insert(R);
    }
    int ans=0;
    for(int i=0;i<n;++i)
    {
        l.erase(l.find(v[i].first));
        r.erase(r.find(v[i].second));
        ans=max(ans,*r.begin()-*l.rbegin());
        l.insert(v[i].first);
        r.insert(v[i].second);
    }
    cout<<ans<<endl;
}

 

#ifndef __AIISP_AI_H__ #define __AIISP_AI_H__ #include "tp_image.h" #include "image_model.h" #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include "hd_debug.h" #include "vendor_videocapture.h" #include "vendor_videoenc.h" #include "vendor_isp.h" #include "vendor_common.h" #include "vendor_ai.h" #include <sys/ipc.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <signal.h> #include <pthread.h> #include <netdb.h> #include <kwrap/file.h> #include "vendor_ai_cpu/vendor_ai_cpu.h" #include "vendor_videoprocess.h" #include "aiisp_isp.h" #define IME_POSTSHARPEN_ENABLE 0 #define AI_ENABLE 1 #define SAVE_RAW_ENABLE 0 #define LOW_ISO_EFFECT 0 #define NORMAL_ISO_EFFECT 1 #define HIGH_ISO_EFFECT 2 #define HDR_ISO_EFFECT 3 #define NET_PATH_ID UINT32 #define LABEL_LEN 256 ///< maximal length of class label #define MAX_CLASS_NUMBER 1000 #define TOP_N 5 #define AIISP_HIGH_GAIN_MODEL "/etc/plugins/aiisp_model_252010.bin" #define AIISP_LOW_GAIN_MODEL "/etc/plugins/aiisp_model_252010_low.bin" #define AIISP_HDR_MODEL "/etc/plugins/aiisp_model_hdr_24112.bin" typedef struct _NET_IN_CONFIG { CHAR input_filename[256]; UINT32 w; UINT32 h; UINT32 c; UINT32 loff; UINT32 fmt; UINT32 type; UINT32 batch; UINT32 time; } NET_IN_CONFIG; typedef struct _NET_PROC_CONFIG { CHAR model_filename[256]; INT32 binsize; CHAR label_filename[256]; } NET_PROC_CONFIG; typedef enum { VPRC_OUTPUT_VOUT, VPRC_OUTPUT_VENC, VPRC_OUTPUT_VENC_1OUT, VPRC_OUTPUT_MAX, ENUM_DUMMY4WORD(VPRC_OUTPUT) } VPRC_OUTPUT; typedef struct _MEM_PARM { UINTPTR pa; UINTPTR va; UINT32 size; UINT32 blk; } MEM_PARM; typedef struct _NOISE_PROFILE { //input blob UINT16 noise_base; UINT16 noise_slope; } NOISE_PROFILE; typedef struct _SNR_STRENGTH { //input blob UINT16 min_motion; UINT16 max_motion; UINT16 min_detail; UINT16 max_detail; } SNR_STRENGTH; typedef struct _USE_REFERENCE { //input blob UINT16 blend; } USE_REFERENCE; typedef struct _NET_PROC { NET_PROC_CONFIG net_cfg; MEM_PARM proc_mem; UINT32 proc_id; CHAR out_class_labels[MAX_CLASS_NUMBER * LABEL_LEN]; MEM_PARM rslt_mem; MEM_PARM io_mem; MEM_PARM intl_mem; VENDOR_AI3_NET_INFO net_info; MEM_PARM input_mem; NOISE_PROFILE noise_profile[3]; SNR_STRENGTH snr_strength[3]; USE_REFERENCE use_reference[3]; } NET_PROC; typedef struct _VIDEO_AIISP_MODEL { NET_PATH_ID net_path; NET_PATH_ID in_path; HD_PATH_ID proc_ctrl; /*需要video.c传入*/ NET_PROC_CONFIG net_proc_cfg; uintptr_t ai_cb; //isp call to ai uintptr_t isp_cb; //ai call to isp }VIDEO_AIISP_MODEL; HD_RESULT aiisp_input_init(void); HD_RESULT aiisp_input_uninit(void); HD_RESULT aiisp_network_init(void); HD_RESULT aiisp_network_uninit(void); INT32 aiisp_network_mem_config(NET_PATH_ID net_path, void* p_cfg); HD_RESULT aiisp_network_open(NET_PATH_ID net_path); HD_RESULT aiisp_network_close(NET_PATH_ID net_path); HD_RESULT aiisp_network_get_ai_cb(VIDEO_AIISP_MODEL *p_stream); HD_RESULT aiisp_network_bind_isp_cb(VIDEO_AIISP_MODEL *p_stream); HD_RESULT aiisp_network_get_param_name(VIDEO_AIISP_MODEL *p_stream, UINT32 para_id, MODEL_PARAM_NAME *p_param_name); HD_RESULT aiisp_network_start(VIDEO_AIISP_MODEL *p_stream); HD_RESULT aiisp_network_stop(VIDEO_AIISP_MODEL *p_stream); #endif 分析一下哪些是关键的ai isp函数
最新发布
09-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值