zoukankan      html  css  js  c++  java
  • 题解 P1047 【校门外的树】

    可以直接模拟,用珂朵莉树是不有点小题大做。

    你怎么做珂朵莉都会骂你:“这么简单的模拟都要用***”

    附赠珂朵莉照片一张

    另外讲几点:

    可以用int,你要不怕MLE

    #include <bits/stdc++.h>
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <string>
    using namespace std;
    int main() {
        bool a[666666];//true 代表a[i]位置有树,false代表a[i]位置上的树已被砍。
        int n,m;
        cin>>n>>m;
        for(int i = 0;i<=n;++i) {//数组初始化为1,因为最开始的时候每个位置都有一棵树
            a[i] = 1;
        }
        int ans = 0;
        while(m--) {
            int start,end;
            cin>>start>>end;
            for(int j = start;j<=end;++j) {//砍树
                a[j] = 0;
            }
        }
        for(int i = 0;i<=n;++i) {
            if(a[i] == 1) {//统计剩余。
                ans++;
            }
        }
        cout<<ans;
    }
    Copyright littlefrog(2019) 所有权利保留。
  • 相关阅读:
    每天一个命令
    2017-2-21
    egrep []+ 和awk总结
    ifconfig eth0 取行取列
    stat /etc/hosts 取行取列644
    压缩解压缩
    目录
    公告
    To do list
    CSP 2019 游记
  • 原文地址:https://www.cnblogs.com/littlefrog/p/11939514.html
Copyright © 2011-2022 走看看