当前位置:网站首页>[daily question] 757. Set the intersection size to at least 2
[daily question] 757. Set the intersection size to at least 2
2022-07-23 07:28:00 【Wang Liuliu, who loves to write bugs】
greedy :
The problem requires us to find the number of minimum point sets , The point set is not specified S It's a continuous segment .
When there is only one line segment , We can take any two points in the line segment as S member , And when there are only two segments , We can make a decision when two line segments coincide :
- When two line segments do not coincide at all , To satisfy the meaning of the question , We need to take two points from each of the two line segments , At this time, these four points can be taken arbitrarily ;
- When only one point of two line segments coincides , To satisfy S Minimize the meaning of the question , We can take the coincidence point first , Then take one of the two line segments ;
- When two or more points of two line segments coincide , At this time, select any two of the coincidence points .
It's not hard to find out , In all cases of coincidence , It must be concluded on the edge of a certain line segment . That is, there is no coincidence point between two line segments , It only occurs in the middle of two line segments :
Therefore, we can start from the edge point decision .
May, in accordance with the 「 The right endpoint is from small to large , The left endpoint ranges from large to small 」 Double keyword sort of , Then deal with each interval from front to back , In the process of processing, it keeps going S Add elements to it , Because we have sorted all the intervals and processed them from front to back , So we go S In the process of adding elements, it must be monotonic , At the same time, consider whether it is necessary to go to the new follow-up interval S When adding elements to meet the meaning of the question , Also with S The biggest of all / Second largest value ( Edge elements in the point set ) compare , So we can use two variables a and b Respectively refer to the current set S The second largest value and the maximum value in (a and b Initialize to a value small enough −1), Without putting the whole S Save it .
边栏推荐
- postman “status“: 500, “error“: “Internal Server Error“, “message“: “The request was rejecte“
- After the applet wx.setstoragesync, sometimes it can't get data with getstoragesync
- Unity notes - use of addressables
- “外卖员的时间没有程序员值钱”:读过书就把自己当人上人?得电
- 直播预告 | openGauss的自治运维平台DBMind实践分享
- 一文理解分布式开发中的服务治理
- Redis common basic configuration files
- A survey of copyright protection research on deep learning model
- DataGrip使用教程(GIF版)
- 程序员45岁之后,绝大部分都被淘汰吗?真相寒了众人的心
猜你喜欢

常用机械设备安全虚拟仿真系统的应用场景及方案

Kotlin learning quick start (8) - Delegation

Analysis of cache read and write strategy

GNU LD脚本命令语言(一)

NFT Insider #67:巴塞罗那足球俱乐部推出首个NFT作品,迪拜推出国家元宇宙战略

Database system design: partition

postman “status“: 500, “error“: “Internal Server Error“, “message“: “The request was rejecte“

编写一个具有搜索提示的搜索框

图像处理解决方案 veImageX 技术演进之路

奇瑞艾瑞泽8产品力超能打,“全优”可不是白叫的
随机推荐
“外卖员的时间没有程序员值钱”:读过书就把自己当人上人?得电
基于以太坊状态数据库的攻击与防御方案
谷歌云和甲骨文云“热崩了”?部署跨云容灾势在必行!
gnu 伪指令定义函数
ESP32:Arduino教程汇总
Unable to open the proxy server. What should I do if the proxy server is not set to full access?
Unity 笔记——Addressables的使用
C语言 程序环境
二叉树的遍历
Zhimeng dedecms forgot to manage the background password retrieval method
AWS uses EC2 to reduce the training cost of deep Racer practical operation of deep racer for cloud
如何制作优质的VR全景?有简单基础的能拍吗?
分享一个qt实现的登录界面模板
【计网实验报告】Cisco局域网模拟组建、简单网络测试
How to quickly shut down the computer shut down command sharing
rs485通信OSI模型网络层
0day attack path prediction method based on network defense knowledge map
Flutter内存泄漏检测
What is the difference between GPU and CPU? Introduction to the meaning of GPU in different computers
数字藏品启动千亿级市场