活动安排,为何我的代码只通过80%

#include <iostream>
#include <algorithm>
using namespace std;
struct dat
{
    int s;
    int f;
    bool operator<(const dat& com)
    {
        return f < com.f;
    }
}dict[1005];

int main()
{
    int n;
    cin >> n;
    int  k = n;
    int index = 0;
    while (k--)
    {
        cin >> dict[index].s >> dict[index].f;
        index++;
    }
    sort(dict, dict + n);

    int ans = 0, t = 0;
    for (int i = 0; i < n; i++)
    {
        if (t < dict[i].s)
        {
            ans++;
            t = dict[i].f;
        }
    }
    cout << ans << endl;
    return 0;
}
全部评论
作者:yWalker 链接:https://ac.nowcoder.com/discuss/212774?type=101&order=0&pos=1&page=0 来源:牛客网  for (int i = 0; i < n; i++)     {         if (t < dict[i].s)         {             ans++;             t = dict[i].f;         }     } 当结束等于开始没有考虑到 如 2 1 3 3 4 应该是2
点赞 回复 分享
发布于 2019-09-01 14:02

相关推荐

在打卡的大老虎很想潜...:你在找实习,没啥实习经历,技术栈放前面,项目多就分两页写,太紧凑了,项目你最多写两个,讲清楚就行,项目背景。用到的技术栈、亮点、难点如何解决,人工智能进面太难了,需求少。你可以加最新大模型的东西
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务