群岛大战(C++)

news/2024/10/23 7:37:57/

群岛大战

  • 英文题目:
    • Problem Statement
    • Constraints
    • Input
    • Output
    • Sample 1
        • Input
        • Output
    • Sample 2
        • Input
        • Output
    • Sample 3
        • Input
        • Output
  • 中文题目:
    • 问题陈述
    • 约束
    • 输出
    • 样本1
        • 输入
        • 输出
    • 样本2
        • 输入
        • 输出
    • 示例3
        • 输入
        • 输出
  • 代码

英文题目:

Problem Statement

There are N N N islands lining up from west to east, connected by N − 1 N−1 N1 bridges.

The i − t h i-th ith bridge connects the i − t h i-th ith island from the west and the ( i + 1 ) − t h (i+1)-th (i+1)th island from the west.

One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:

Request i i i: A dispute took place between the a i − t h a_i-th aith island from the west and the b i − t h b_i-th bith island from the west. Please make traveling between these islands with bridges impossible.

You decided to remove some bridges to meet all these M M M requests.

Find the minimum number of bridges that must be removed.

Constraints

All values in input are integers.
2 ≤ N ≤ 1 0 5 2 \leq N \leq 10^5 2N105
1 ≤ M ≤ 1 0 5 1 \leq M \leq 10^5 1M105
1 ≤ a i < b i ≤ N 1 \leq a_i < b_i \leq N 1ai<biN
All pairs ( a i , b i ) (a_i, b_i) (ai,bi) are distinct.

Input

Input is given from Standard Input in the following format:

N M N M NM
a 1 a_1 a1 b 1 b_1 b1
a 2 a_2 a2 b 2 b_2 b2
: : :
a M a_M aM b M b_M bM

Output

Print the minimum number of bridges that must be removed.

Sample 1

Input

5 2
1 4
2 5

Output

1

The requests can be met by removing the bridge connecting the second and third islands from the west.

Sample 2

Input

9 5
1 8
2 7
3 5
4 6
7 9

Output

2

Sample 3

Input

5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

Output

4

中文题目:

问题陈述

这里有 N N N岛屿,从西向东排列,由 N − 1 N−1 N1桥梁连接。

i − t h i-th ith桥连接了西面的 i − t h i-th ith岛和西面的 ( i + 1 ) − t h (i+1)-th (i+1)th岛。

一天,一些岛屿之间发生了争端,岛上的居民提出了M个请求:

请求 i i i:在西面的 a i − t h a_i-th aith岛和西面的 b i − t h b_i-th bith岛之间发生了争端。请不要在这些岛屿之间搭桥。

您决定删除一些桥以满足所有这些 M M M请求。

找出必须拆除的桥的最小数量。

约束

输入中的所有值都是整数。
2 ≤ N ≤ 1 0 5 2 \leq N \leq 10^5 2N105
1 ≤ M ≤ 1 0 5 1 \leq M \leq 10^5 1M105
1 ≤ a i < b i ≤ N 1 \leq a_i < b_i \leq N 1ai<biN
所有对 ( a i , b i ) (a_i, b_i) (ai,bi)都是不同的。
##输入
标准输入的输入格式如下:

N M N M NM
a 1 a_1 a1 b 1 b_1 b1
a 2 a_2 a2 b 2 b_2 b2
: : :
a M a_M aM b M b_M bM

输出

打印必须移除的桥的最小数量。

样本1

输入

5 2
14
2 5

输出

1

通过拆除连接西部第二和第三岛屿的桥梁,可以满足这些要求。

样本2

输入

9 5
18
27
3 5
4 6
7 9

输出

2

示例3

输入

5 10
1 2
1 3
14
15
2 3
2 4
2 5
3 4
3 5
4 5

输出

4

代码

#include<bits/stdc++.h>
using namespace std;
struct node{int x,y; } a[1200000];
int n,m,s,mi; 
bool cmp(node a,node b)
{if(a.y==b.y)return a.x<b.x;return a.y<b.y;
}
int main() 
{cin >>n >>m;for (int i=1;i<=m;i++){cin >>a[i].x >>a[i].y;mi=min(mi,a[i].y);}sort(a+1,a+m+1,cmp);for(int i=1;i<=m;i++){if(a[i].x>=mi){s++;mi=a[i].y;}}cout <<s;return 0;
}

http://www.ppmy.cn/news/75985.html

相关文章

一文把 JavaScript 中的 this 聊得明明白白

文章目录 1.this 是什么&#xff1f;2.this的指向2.1 全局上下文的 this 指向2.2 函数&#xff08;普通函数&#xff09;上下文中的 this 指向2.3 事件处理程序中的 this 指向2.4 以对象的方式调用时 this 的指向2.5 构造函数中的 this 指向2.6 在 类上下文中 this 的指向。2.7…

Flink第五章:处理函数

系列文章目录 Flink第一章:环境搭建 Flink第二章:基本操作. Flink第三章:基本操作(二) Flink第四章:水位线和窗口 Flink第五章:处理函数 文章目录 系列文章目录前言一、基本处理函数(ProcessFunction)二、按键分区处理函数&#xff08;KeyedProcessFunction&#xff09;1.处理…

一、尚医通登录需求

文章目录 一、登录需求1、登录效果2、登录需求 二、登录1&#xff0c;搭建service-user模块1.1 搭建service-user模块1.2 修改配置1.3 启动类1.4 配置网关 2、添加用户基础类2.1 添加model2.2 添加Mapper2.3 添加service接口及实现类2.4 添加controller 3、登录api接口3.1 添加…

linux系统升级/更新OpenSSL版本操作流程记录

问题描述&#xff1a;有时 OpenSSL 版本过老升级&#xff0c;或者需要更新 OpenSSL 版本 1. 登录 linux 系统后输入 openssl version 查看现在使用的版本 我的输入后版本信息为&#xff1a;OpenSSL 1.1.1g FIPS 21 Apr 2020 &#xff0c;可以看到是一年前更新版本&#xff0c;…

深入浅出 SQL Server CDC 数据同步

简介 SQL Server 是一款老牌关系型数据库,自 1988 年由 Microsoft、Sybase 和 Ashton-Tate 三家公司共同推出&#xff0c;不断迭代更新至今&#xff0c;拥有相当广泛的用户群体。 如今&#xff0c;我们提到 SQL Server 通常指 Microsoft SQL Server 2000 之后的版本。 SQL S…

网络安全里主要的岗位有哪些?小白如何快速入门学习黑客?

入门Web安全、安卓安全、二进制安全、工控安全还是智能硬件安全等等&#xff0c;每个不同的领域要掌握的技能也不同。 当然入门Web安全相对难度较低&#xff0c;也是很多人的首选。主要还是看自己的兴趣方向吧。 本文就以下几个问题来说明网络安全大致学习过程&#x1f447; 网…

什么是jquery jq的基本使用

JQuery的概述 jQuery是一个快速的&#xff0c;简洁的javaScript库&#xff0c;使用户能更方便地处理HTML documents、events、实现动画效果&#xff0c;并且方便地为网站提供AJAX交互。 jQuery能够使用户的html页保持代码和html内容分离&#xff0c;也就是说&#xff0c…

Java高并发核心编程—CAS与JUC原子类

注&#xff1a;本笔记是阅读《Java高并发核心编程卷2》整理的笔记&#xff01; CAS原理 JUC原子类一Atomic 基本原子类 数组原子类 引用原子类 字段更新原子类 AtomicInteger 线程安全原理 引用类型原子类 属性更新原子类 ABA问题 提升高并发场景下CAS提作的性能 以空间换时间:…