集合帖:区间问题
一、AcWing 803:区间合并
(1)题目来源:https://www.acwing.com/problem/content/805/
(2)算法代码:https://blog.csdn.net/hnjzsyjyj/article/details/145067059
#include <bits/stdc++.h>
using namespace std;const int maxn=1e5+5;
struct Section {int x;int y;
} a[maxn];bool cmp(Section u,Section v) {if(u.x==v.x) return u.y<v.y;return u.x<v.x;
}int main() {int n;cin>>n;for(int i=1; i<=n; i++) {cin>>a[i].x>>a[i].y;}sort(a+1,a+1+n,cmp);int base=a[1].y;int cnt=1;for(int i=1; i<=n; i++) {if(a[i].x<=base) base=max(base,a[i].y);else cnt++,base=a[i].y;}cout<<cnt<<endl;return 0;
}/*
in:
10
-15 -8
-20 23
-2 11
2 22
18 23
11 27
-8 21
-18 14
-17 -12
-23 8
out:
1
*/
二、洛谷 P1496:火烧赤壁
(1)题目来源:https://www.luogu.com.cn/problem/P1496
(2)算法代码:https://blog.csdn.net/hnjzsyjyj/article/details/145073398
#include <bits/stdc++.h>
using namespace std;const int maxn=2e5;
struct Point {int x;int y;
} a[maxn];bool cmp(Point u,Point v) {if(u.x==v.x) return u.y<v.y;return u.x<v.x;
}int main() {int n;cin>>n;for(int i=1; i<=n; i++) {cin>>a[i].x>>a[i].y;}sort(a+1,a+1+n,cmp);int cnt=0;int from=a[1].x;int base=a[1].y;for(int i=1; i<=n; i++) {if(a[i].x<=base) base=max(base,a[i].y);else {cnt+=(base-from);from=a[i].x;base=a[i].y;}}cnt+=(base-from);cout<<cnt<<endl;return 0;
}/*
in:
3
-1 1
5 11
2 9
out:
11
*/
三、AcWing 905:区间选点
(1)题目来源:https://www.acwing.com/problem/content/907/
(2)算法代码:https://blog.csdn.net/hnjzsyjyj/article/details/142840548
#include <bits/stdc++.h>
using namespace std;const int inf=0x3f3f3f3f;
const int maxn=1e5+5;struct Scope {int le,ri;
} a[maxn];bool up(Scope u,Scope v) {return u.ri<v.ri;
}int main() {int n;cin>>n;for(int i=0; i<n; i++) {cin>>a[i].le>>a[i].ri;}sort(a,a+n,up);int ans=0;int t_ri=-inf;for(int i=0; i<n; i++)if(t_ri<a[i].le) {ans++;t_ri=a[i].ri;}cout<<ans<<endl;return 0;
}/*
in:
3
-1 1
2 4
3 5
out:
2
*/
四、AcWing 906:区间分组
(1)题目来源:https://www.acwing.com/problem/content/908/
(2)算法代码:https://blog.csdn.net/hnjzsyjyj/article/details/145081557
#include <bits/stdc++.h>
using namespace std;const int maxn=1e5+5;
pair<int,int> a[maxn];
int n;int main() {cin>>n;for(int i=0; i<n; i++) {cin>>a[i].first>>a[i].second;}sort(a,a+n);priority_queue<int,vector<int>,greater<int>> q;for(int i=0; i<n; i++) {if(q.size() && a[i].first>q.top()) q.pop();q.push(a[i].second);}cout<<q.size()<<endl;return 0;
}/*
in:
10
-15 -8
-20 23
-2 11
2 22
18 23
11 27
-8 21
-18 14
-17 -12
-23 8out:
6
*/
五、AcWing 907:区间覆盖
(1)题目来源:https://www.acwing.com/problem/content/909/
(2)算法代码:https://blog.csdn.net/hnjzsyjyj/article/details/145083747
#include <bits/stdc++.h>
using namespace std;const int maxn=1e5+5;
struct Section {int x;int y;
} a[maxn];bool cmp(Section u,Section v) {if(u.x==v.x) return u.y<v.y;return u.x<v.x;
}int main() {int st,en;cin>>st>>en;int n;cin>>n;for(int i=1; i<=n; i++) {cin>>a[i].x>>a[i].y;}sort(a+1,a+1+n,cmp);int ans=0;bool flag=false;for(int i=1; i<=n; i++) {int j=i,t=INT_MIN;while(j<=n && a[j].x<=st) {t=max(t,a[j].y);j++;}if(t<st) break;ans++;if(t>=en) {flag=true;break;}st=t,i=j-1;}if(!flag) ans=-1;cout<<ans<<endl;return 0;
}/*
in:
1 5
3
-1 3
2 4
3 5out:
2
*/
六、AcWing 802:区间和
(1)题目来源:https://www.acwing.com/problem/content/804/
(2)算法代码:https://blog.csdn.net/hnjzsyjyj/article/details/143309807
#include <bits/stdc++.h>
using namespace std;typedef pair<int,int> PII;
const int maxn=3e5+5;
int a[maxn],s[maxn];
int n,m;
vector<int> alls;
vector<PII> add,query;int find(int x) { //discretizationint le=0;int ri=alls.size()-1;while(le<ri) {int mid=(le+ri)>>1;if(alls[mid]>=x) ri=mid;else le=mid+1;}return ri+1;
}int main() {cin>>n>>m;for(int i=0; i<n; i++) {int x,c;cin>>x>>c;alls.push_back(x);add.push_back({x,c});}for(int i=0; i<m; i++) {int le,ri;cin>>le>>ri;alls.push_back(le), alls.push_back(ri);query.push_back({le,ri});}//de-weightsort(alls.begin(),alls.end());alls.erase(unique(alls.begin(),alls.end()), alls.end());for(auto v:add) {int x=find(v.first);a[x]+=v.second;}for(int i=1; i<=alls.size(); i++) {s[i]=s[i-1]+a[i]; //prefix sum}for(auto v:query) {int le=find(v.first);int ri=find(v.second);cout<<s[ri]-s[le-1]<<endl;}return 0;
}/*
in:
3 3
1 2
3 6
7 5
1 3
4 6
7 8
out:
8
0
5
*/
相关文章:
集合帖:区间问题
一、AcWing 803:区间合并 (1)题目来源:https://www.acwing.com/problem/content/805/ (2)算法代码:https://blog.csdn.net/hnjzsyjyj/article/details/145067059 #include <bits/stdc.h>…...
C#,入门教程(27)——应用程序(Application)的基础知识
上一篇: C#,入门教程(26)——数据的基本概念与使用方法https://blog.csdn.net/beijinghorn/article/details/124952589 一、什么是应用程序 Application? 应用程序是编程的结果。一般把代码经过编译(等)过程&#…...
迅翼SwiftWing | ROS 固定翼开源仿真平台正式发布!
经过前期内测调试,ROS固定翼开源仿真平台今日正式上线!现平台除适配PX4ROS环境外,也已实现APROS环境下的单机飞行控制仿真适配。欢迎大家通过文末链接查看项目地址以及具体使用手册。 1 平台简介 ROS固定翼仿真平台旨在实现固定翼无人机决策…...
CSS 样式 box-sizing: border-box; 详细解读
box-sizing是 CSS 中的一个属性,用于控制元素的盒模型计算方式。border-box值表示元素的宽度和高度将包括内边距(padding)和边框(border),而不仅仅是内容的宽度和高度。这意味着当你为元素设置宽度和高度时…...
FLASK创建下载
html用a标签 <!-- Button to download the image --> <a href"{{ url_for(download_file, filenameimage.png) }}"><button>Download Image</button> </a> 后端:url_for双大括号即是用来插入变量到模板中的语法。也就是绑…...
漫话架构师|什么是系统架构设计师(开篇)
~犬📰余~ “我欲贱而贵,愚而智,贫而富,可乎? 曰:其唯学乎” 关注犬余,共同进步 技术从此不孤单...
Web Socket
Web Socket WebSocket是一种基于TCP的网络通信协议,允许客户端和服务器之间建立全双工(双向)通信通道。WebSocket通过HTTP协议进行握手,建立连接后,客户端和服务器可以在同一个连接上同时发送和接收数据࿰…...
JavaSE学习心得(反射篇)
反射 前言 获取class对象的三种方式 利用反射获取构造方法 利用反射获取成员变量 利用反射获取成员方法 练习 保存信息 跟配置文件结合动态创建 前言 接上期文章:JavaSE学习心得(多线程与网络编程篇) 教程链接:黑马…...
使用FRP进行内网穿透
一、基本概念 内网穿透:它是一种网络技术或方法,旨在允许外部网络(如互联网)访问位于内部网络(内网)中的设备或服务。由于内部网络通常处于NAT(网络地址转换)、防火墙或其他安全机制…...
长安“战疫”网络安全公益赛的一些随想
起因 今年刚进入大学,开始带校队,为了培养校队新成员,也就一直计划着和当地的一些高校合作交流,但是由于种种原因一直被搁置下来。正巧学校信息中心和四叶草有一个培训项目的合作,学校的网安协会也算是沾了光成为了培…...
flutter 安卓端打包
在 Flutter 中打包 Android 应用程序是一个相对简单的过程。你可以使用 Flutter 的命令行工具来构建并打包你的 APK 或 AAB(Android App Bundle)。以下是打包 Flutter Android 应用的步骤: 1. 安装 Flutter 环境 确保你已经安装了 Flutter …...
Cesium中的CustomDataSource 详解
Cesium CustomDataSource 详解 在 Cesium 中,CustomDataSource 是一个强大的类,用于处理自定义的地理数据。它提供了一种方法,可以通过程序方式添加、管理和更新动态的地理实体,而无需依赖外部数据格式(如 GeoJSON 或…...
[Qt]常用控件介绍-按钮类控件-QPushButton、QRedioButton、QCheckBox、QToolButton控件
目录 1.QPushButton按钮 介绍 属性 Demo:键盘方向键控制人物移动 2.Redio Button按钮 属性 clicked、pressed、released、toggled区别 单选按钮的分组 Demo:点餐小程序 3.CheckBox按钮 属性 Demo:获取今天的形成计划 4.ToolBu…...
Windows 蓝牙驱动开发-安装蓝牙设备
蓝牙配置文件驱动程序有两种安装类型: 客户端安装,在此类安装中,远程设备播发其服务,并且计算机与之连接。 示例包括:鼠标、键盘和打印机;服务器端安装,在此类安装中,计算机播发服务…...
element表格有横向滚动条时产生错位或者偏移(火狐浏览器)
问题图 解决方法:给表头增加竖向滚动条的宽度 // 解决拖拽表格滚动条,错位问题 ::v-deep .el-table__header-wrapper{padding-right: 20px!important; // 滚动条宽度 }效果图如下:...
C# 下 SQLite 并发操作与锁库问题的 5 种解决方案
开篇:你是否被 SQLite 并发锁库困扰? 在当今数字化的时代浪潮中,数据已然成为了企业与开发者们手中最为宝贵的资产之一。C# 作为一门广泛应用于各类软件开发的强大编程语言,常常需要与数据库进行紧密交互,以实现数据的…...
2025封禁指定国家ip-安装xtables-addons记录
如何安装和使用 安装lux仓库(该仓库包含xtables-addons所需的依赖环境) # wget http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm # rpm -ivh lux-release-7-1.noarch.rpm 安装xtables-addons。注意:必须先安装kmod-xtables-addons,再…...
卷积神经02-CUDA+Pytorch环境安装
卷积神经02-CUDAPytorch环境安装 在使用Python进行pytorch的使用过程中遇到各种各样的版本冲突问题,在此进行记录 0-核心知识脉络 1)根据自己电脑的CUDA版本安装对应版本的Pytorch,充分的使用GPU性能2)电脑要先安装【CUDA ToolKi…...
高斯数据库与MySQL数据库的区别
高斯数据库与MySQL数据库的区别 在当今数据驱动的时代,选择合适的数据库管理系统(DBMS)对于项目的成功至关重要。高斯数据库和MySQL作为两款广泛使用的数据库系统,各自具有独特的特点和优势,适用于不同的应用场景。本…...
【 PID 算法 】PID 算法基础
一、简介 PID即:Proportional(比例)、Integral(积分)、Differential(微分)的缩写。也就是说,PID算法是结合这三种环节在一起的。粘一下百度百科中的东西吧。 顾名思义,…...
C++初阶-list的底层
目录 1.std::list实现的所有代码 2.list的简单介绍 2.1实现list的类 2.2_list_iterator的实现 2.2.1_list_iterator实现的原因和好处 2.2.2_list_iterator实现 2.3_list_node的实现 2.3.1. 避免递归的模板依赖 2.3.2. 内存布局一致性 2.3.3. 类型安全的替代方案 2.3.…...
376. Wiggle Subsequence
376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...
Unity | AmplifyShaderEditor插件基础(第七集:平面波动shader)
目录 一、👋🏻前言 二、😈sinx波动的基本原理 三、😈波动起来 1.sinx节点介绍 2.vertexPosition 3.集成Vector3 a.节点Append b.连起来 4.波动起来 a.波动的原理 b.时间节点 c.sinx的处理 四、🌊波动优化…...
重启Eureka集群中的节点,对已经注册的服务有什么影响
先看答案,如果正确地操作,重启Eureka集群中的节点,对已经注册的服务影响非常小,甚至可以做到无感知。 但如果操作不当,可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...
SQL慢可能是触发了ring buffer
简介 最近在进行 postgresql 性能排查的时候,发现 PG 在某一个时间并行执行的 SQL 变得特别慢。最后通过监控监观察到并行发起得时间 buffers_alloc 就急速上升,且低水位伴随在整个慢 SQL,一直是 buferIO 的等待事件,此时也没有其他会话的争抢。SQL 虽然不是高效 SQL ,但…...
PHP 8.5 即将发布:管道操作符、强力调试
前不久,PHP宣布了即将在 2025 年 11 月 20 日 正式发布的 PHP 8.5!作为 PHP 语言的又一次重要迭代,PHP 8.5 承诺带来一系列旨在提升代码可读性、健壮性以及开发者效率的改进。而更令人兴奋的是,借助强大的本地开发环境 ServBay&am…...
Chromium 136 编译指南 Windows篇:depot_tools 配置与源码获取(二)
引言 工欲善其事,必先利其器。在完成了 Visual Studio 2022 和 Windows SDK 的安装后,我们即将接触到 Chromium 开发生态中最核心的工具——depot_tools。这个由 Google 精心打造的工具集,就像是连接开发者与 Chromium 庞大代码库的智能桥梁…...
pikachu靶场通关笔记19 SQL注入02-字符型注入(GET)
目录 一、SQL注入 二、字符型SQL注入 三、字符型注入与数字型注入 四、源码分析 五、渗透实战 1、渗透准备 2、SQL注入探测 (1)输入单引号 (2)万能注入语句 3、获取回显列orderby 4、获取数据库名database 5、获取表名…...
vue3 daterange正则踩坑
<el-form-item label"空置时间" prop"vacantTime"> <el-date-picker v-model"form.vacantTime" type"daterange" start-placeholder"开始日期" end-placeholder"结束日期" clearable :editable"fal…...
jdbc查询mysql数据库时,出现id顺序错误的情况
我在repository中的查询语句如下所示,即传入一个List<intager>的数据,返回这些id的问题列表。但是由于数据库查询时ID列表的顺序与预期不一致,会导致返回的id是从小到大排列的,但我不希望这样。 Query("SELECT NEW com…...
