1 条题解

  • 0
    @ 2022-02-13 21:31:51

    这一题是个很简单的贪心,将ans定为1,找到t为结束时间最早的,只要下一个的开始时间>=t,就代表可行,ans++,更新t。最后输出ans即可
    #include<bits/stdc++.h>
    using namespace std;
    int n,t,ans;
    struct note
    {
    int st;
    int ed;
    }w[1010];
    bool cmp(note x,note y)
    {
    return x.ed<y.ed;
    }
    int main()
    {
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    cin>>w[i].st>>w[i].ed;
    }
    sort(w+1,w+n+1,cmp);
    t=w[1].ed;
    ans=1;
    for(int i=2;i<=n;i++)
    {
    if(w[i].st>=t)
    {
    ans++;
    t=w[i].ed;
    }
    }
    cout<<ans;
    return 0;
    }

  • 1

「一本通 1.1 例 1」活动安排

信息

难度
5
分类
贪心 点击显示
标签
递交数
68
已通过
23
通过率
34%
被复制
4
上传者