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
这段代码是一个 **AI ISP(Artificial Intelligence-based Image Signal Processing)模块的头文件**,定义了 AI ISP 模块所需的数据结构、模型路径、内存配置、以及关键函数接口。它主要用于 **AI 与 ISP 模块之间的协作处理图像**,实现如去噪、HDR 合成、图像增强等功能。 --- ## 🧠 关键 AI ISP 函数分析 以下是从该头文件中提取出的 **关键 AI ISP 函数**,它们构成了 AI ISP 模块的核心流程。 --- ### ✅ 1. `HD_RESULT aiisp_input_init(void);` **功能**:初始化 AI ISP 的输入模块。 **说明**:用于配置输入图像的格式、尺寸、内存分配等,为后续 AI 处理做准备。 --- ### ✅ 2. `HD_RESULT aiisp_input_uninit(void);` **功能**:去初始化 AI ISP 的输入模块。 **说明**:释放输入模块资源,如内存、DMA 缓冲区等。 --- ###3. `HD_RESULT aiisp_network_init(void);` **功能**:初始化 AI 网络模型。 **说明**:加载 AI 模型文件(如 `.bin` 文件),为图像处理做准备。 --- ### ✅ 4. `HD_RESULT aiisp_network_uninit(void);` **功能**:去初始化 AI 网络模型。 **说明**:释放模型资源,关闭模型加载器。 --- ### ✅ 5. `INT32 aiisp_network_mem_config(NET_PATH_ID net_path, void* p_cfg);` **功能**:配置 AI 网络的内存参数。 **说明**:设置输入输出缓冲区大小、内存地址等,确保数据正确传输。 --- ### ✅ 6. `HD_RESULT aiisp_network_open(NET_PATH_ID net_path);` **功能**:打开指定路径的 AI 网络模型。 **说明**:根据 `net_path` 加载对应的 AI 模型(如 HDR 模型、高 ISO 模型)。 --- ### ✅ 7. `HD_RESULT aiisp_network_close(NET_PATH_ID net_path);` **功能**:关闭指定路径的 AI 网络模型。 **说明**:释放模型占用的资源。 --- ### ✅ 8. `HD_RESULT aiisp_network_get_ai_cb(VIDEO_AIISP_MODEL *p_stream);` **功能**:获取 AI 模块的回调函数。 **说明**:用于 ISP 调用 AI 模块处理图像数据(如去噪、HDR 合成)。 --- ### ✅ 9. `HD_RESULT aiisp_network_bind_isp_cb(VIDEO_AIISP_MODEL *p_stream);` **功能**:绑定 ISP 模块的回调函数到 AI 模块。 **说明**:使 AI 模块可以调用 ISP 的函数(如获取图像参数、设置 ISP 参数)。 --- ### ✅ 10. `HD_RESULT aiisp_network_get_param_name(VIDEO_AIISP_MODEL *p_stream, UINT32 para_id, MODEL_PARAM_NAME *p_param_name);` **功能**:获取 AI 模型中某个参数的名称。 **说明**:用于调试或配置 AI 模型参数。 --- ### ✅ 11. `HD_RESULT aiisp_network_start(VIDEO_AIISP_MODEL *p_stream);` **功能**:启动 AI ISP 处理流程。 **说明**:开始将图像数据送入 AI 模型进行处理(如去噪、HDR 合成)。 --- ### ✅ 12. `HD_RESULT aiisp_network_stop(VIDEO_AIISP_MODEL *p_stream);` **功能**:停止 AI ISP 处理流程。 **说明**:暂停或终止 AI 模型的图像处理流程。 --- ## 🧩 结构体中的关键回调字段 ```c typedef struct _VIDEO_AIISP_MODEL { ... uintptr_t ai_cb; // ISP 调用 AI 的回调 uintptr_t isp_cb; // AI 调用 ISP 的回调 }VIDEO_AIISP_MODEL; ``` - **`ai_cb`**:ISP 调用 AI 的接口,用于将图像数据传入 AI 模型进行处理。 - **`isp_cb`**:AI 调用 ISP 的接口,用于获取图像状态(如 ISO、gain、动态范围)。 --- ## 📌 AI ISP 的典型流程 ``` aiisp_input_init() → aiisp_network_init() → aiisp_network_open() → aiisp_network_bind_isp_cb() → aiisp_network_start() → aiisp_network_stop() → aiisp_network_close() → aiisp_network_uninit() → aiisp_input_uninit() ``` --- ## ✅ 总结一句话: 这段头文件中定义的 **AI ISP 关键函数包括输入初始化、模型加载、内存配置、回调绑定、处理启动与停止等**,构成了 AI 与 ISP 协同工作的完整流程。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值