P1047简单吗?

P1047 [NOIP2005 普及组] 校门外的树

YXC20142024 @ 2024-12-13 19:03:04

P1047 [NOIP2005 普及组] 校门外的树咋做?


by zjz11223 @ 2024-12-13 19:37:20

#include <bits/stdc++.h>
using namespace std;

int l, m; //l颗树,m个区域
bool b[10001];

int main()
{    //初始化:
    //归"false":
    memset(b, 1, sizeof(b));

    //输入:
    scanf("%d%d", &l, &m);

    //计算答案:
    for(int i = 1; i <= m; ++i) {
        int u, v; //从第u点开始到第v点结束,这一段是地铁
        scanf("%d%d", &u, &v);
        for(int j = u; j <= v; ++j) {
            b[j] = 0; //这里被建成地铁了
        }
    }

    //输出:
    int ans = 0;
    for(int i = 1; i <= l; ++i) {
        if(b[i]) {
            //没被移走
            ++ans;
        }
    }
    printf("%d\n", ans);

    return 0;
}

by cqfcbb2015 @ 2024-12-13 19:40:58

这题我采用的是桶数组,你可以用STL::MAP,根据题目意思来画出铁路


by zjz11223 @ 2024-12-13 19:43:45

答: 用模拟, 很简单


by _xguagua_Firefly_ @ 2024-12-19 07:55:05

用数据结构维护颜色段均摊,然后数颜色就好了(


by liuyc0120 @ 2024-12-19 22:27:08

难难难!!!


by l_sbh_rx @ 2024-12-19 23:04:57

@_xguaguaFirefly老司机[手动狗头]


by _xguagua_Firefly_ @ 2024-12-20 07:37:29

@l_sbh_rx

:)


|