十五月明


私信TA

用户名:dotcpp0605328

访问量:2647

签 名:

等  级
排  名 510
经  验 4415
参赛次数 0
文章发表 68
年  龄 18
在职情况 学生
学  校 曲阜师范大学
专  业 人工智能

  自我简介:

Easy

解题思路:

注意事项:

参考代码:

#include<iostream>

#include<algorithm>

using namespace std;

const int N = 1000000;

struct node

{

    int start,end;

}a[N];

bool cmp(node x,node y){return x.end<y.end;}

int main()

{

    int n;cin>>n;

    for(int i=0;i<n;i++)cin>>a[i].start>>a[i].end;

    sort(a,a+n,cmp);

    int res=1;//第一个也得算进去

    int temp=a[0].end;

    for(int i=1;i<n;i++)

    {

        if(temp<=a[i].start)

        {

            res++;

            temp=a[i].end;

        }

    }

    cout<<res<<endl;

    return 0;

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区