只有前两个WA其他全部AC什么情况。。?
查看原帖
只有前两个WA其他全部AC什么情况。。?
1077289
ALittleS0v1etCAT楼主2023/8/30 21:34
#include <iostream>

using namespace std;

int main()
{
    int length,numOfSections; //数组长度,区间个数
    cin >> length;
    bool* trees = new bool[length]; // 利用指针声明动态变量
    for (size_t i = 0; i < length; i++) // 初始化,全部设为true
    {
        trees[i] = true;
    }
    cin >> numOfSections;
    for (size_t i = 0; i < numOfSections; i++) // 输入区间部分
    {
        int startOfSection=0,endOfSection=0; // 开始坐标,结束坐标
        cin >> startOfSection;
        cin >> endOfSection;
        for (size_t j = startOfSection; j < endOfSection; j++) // 循环将区间内的树设为false
        {
            trees[j] = false;
        }
    }
    int numOfTreesLeft=0; // 统计剩下的树
    for (size_t i = 0; i < length; i++)
    {
        if (trees[i]) // 由于数组类型是bool,所以直接利用条件判断累加
        {
            ++numOfTreesLeft; // 前++似乎效率更高
        }
        
    }
    cout << numOfTreesLeft; // 输出
    return 0;
}

输出: 输出

2023/8/30 21:34
加载中...