当前位置: 首页 > news >正文

枚举 · 例8扩展-校门外的树:hard

登录—专业IT笔试面试备考平台_牛客网

代码区:

#include<algorithm>
#include<iostream>
#include<vector>using namespace std;
struct TREE{int left,right;
};
bool compare(const  TREE&a,const TREE& b ){if(a.left!=b.left){return a.left<b.left;}return a.right<b.right;
}
int main(){long long l,n,move_count=0;cin>>l>>n;vector<struct TREE> tree(n);for(int i=0;i<n;i++){int a,b;cin>>a>>b;struct TREE temp_tree;temp_tree.left=a;temp_tree.right=b;tree[i]=temp_tree;}//按照左端点升序排列,左端点相同,按照右端点升序排列sort(tree.begin(),tree.end(),compare);//如何判断是否存在覆盖区域int current_right=-1;for(int i=0;i<n;i++){//不存在覆盖区域,下一个区域的左端点>本次区域的右端点if(tree[i].left>current_right){move_count+=(tree[i].right-tree[i].left+1);current_right=tree[i].right;}//存在覆盖区域,只需要加上未被覆盖的部分else if(tree[i].right>current_right){move_count+=(tree[i].right-current_right);current_right=tree[i].right;}}cout<<l+1-move_count;return 0;
}

欢迎各位读者提出意见。

(菜菜奋斗小日记)

http://www.dtcms.com/a/179007.html

相关文章:

  • Java:跨越时代的编程语言,持续引领技术变革
  • 每日学习Java之一万个为什么(待完善)
  • ABP vNext + Dapr 实现云原生微服务治理
  • NGINX `ngx_http_gzip_static_module` 零时延送出预压缩文件
  • 没有Mac,我是怎么上传IPA到App Store的?
  • 15.thinkphp的上传功能
  • CAP理论:分布式系统的权衡
  • K8S - 蓝绿发布实战 - Argo Rollouts 零停机方案解析
  • MCP 工具速成:npx vs. uvx 全流程安装指南
  • macOS Arduino IDE离线安装ESP8266支持包
  • Python程序,输入IP,扫描该IP哪些端口对外是开放的,输出端口列表
  • k8s术语之secret
  • SLAM文献之KernelGPA: A Globally Optimal Solution to Deformable SLAM in Closed-form
  • 宏观经济2
  • 自学嵌入式 day 16-c语言-第10章 指针
  • 基于redis的定时状态更新
  • 【c++】继承详解
  • UOS安装AMD显卡驱动
  • AI优化高频PCB信号完整性:猎板PCB的技术突破与应用实践
  • PCIe控制器介绍(二)
  • RDD实现单词计数
  • TDengine 在新能源行业应用
  • 华为网路设备学习-21 路由过滤(filter-policy)
  • C++ STL入门:set 集合容器
  • TDEngine 与 Grafana
  • Unicode字符集字符流
  • QT:获取软件界面窗口的尺寸大小2025.5.8
  • Java—— 集合 Collection
  • [GESP202409 六级] 小杨和整数拆分 Java
  • ​​​​​​​MySQL数据库故障排查指南