文章

1

粉丝

0

获赞

0

访问

47

头像
种树2 题解:贪心
P801
发布于2026年3月7日 09:18
阅读数 47

区间调度 + 优先从后往前种

#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

struct suggestion
{
    int start;
    int end;
    int tree;
};

bool cmp(suggestion s1, suggestion s2) {
    return s1.end < s2.end;
}

int main() {
    int n, h;
    cin >> n;
    cin >> h;
    vector<suggestion> date;
    
    for (int i = 0; i < h; i++) {
        suggestion tmp;
        cin >> tmp.start >> tmp.end >> tmp.tree;
        date.push_back(tmp);
    }
    sort(date.begin(), date.end(), cmp);
    vector<int> trees(n + 1);
    int result = 0;
    for (int i = 0; i < h; i++) {
        int current = 0;
        for (int j = da...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发