信奥题解

种树

https://ac.nowcoder.com/acm/contest/950/B

贪心的基本思想,为防止错误要把握好精度。
刷满1000题,与君共勉!!!

//https://ac.nowcoder.com/acm/contest/950/B
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e4 + 5;
struct nowcode
{
    int b, e, t;
} cow[5005];
int q[MAX] = {0};
bool cmp(nowcode one, nowcode two)
{
    return one.e < two.e;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, h;
    cin >> n >> h;
    for (int i = 0; i < h; ++i)
    {
        cin >> cow[i].b >> cow[i].e >> cow[i].t;
    }
    sort(cow, cow + h, cmp);
    int ans = 0;
    for (int i = 0; i < h; ++i)
    {
        int count = 0;
        for (int j = cow[i].b; j <= cow[i].e; ++j)
        {
            if (q[j] == 1)
            {
                count++;
            }
        }
        if (count < cow[i].t)
        {
            for (int j = cow[i].e; j >= cow[i].b; --j)
            {
                if (q[j] == 0)
                {
                    q[j] = 1;
                    count++;
                    ans++;
                }
                if (count == cow[i].t)
                {
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    system("pause");
    return 0;
}
全部评论

相关推荐

今天投了小鹏,收到了AI面,大概会问哪些啊?
期末一定及格:总共4个部分,心理测评、行测、然后就是问岗位、对岗位的理解、过往遇到了哪些难点怎么解决,很简单,没有什么特别专业的问题,都是一些综合素质相关的
小鹏汽车AI面4人在聊
点赞 评论 收藏
分享
Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
Ncsbbss:又想干活又想要工资,怎么什么好事都让你占了
点赞 评论 收藏
分享
我:“加班需要有加班工资。”&nbsp;hr:“为什么?”&nbsp;哈哈哈哈哈哈哈离大谱
juntenor:你确实太理想化了,对社会不了解呀。这个和HR没有关系,这是国内特色,不然怎么还会有外包就这种逆天的存在呢。
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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