活动安排,为何我的代码只通过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

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务