美文网首页
2020-09-01 校门外的树

2020-09-01 校门外的树

作者: JalorOo | 来源:发表于2020-09-01 23:27 被阅读0次

https://www.luogu.com.cn/problem/P1047

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

long long qmi(int m, int k)
{
    int res = 1, t = m;
    while (k)
    {
        if (k&1) res = res * t;
        t = t * t;
        k >>= 1;
    }
    return res;
}

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}

#define fi(a,b) for(int i = a; i <= b; i++)
#define fj(a,b) for(int j = a; j >= b; j--)

//以上不解释
int L,M;
//变量名称与原题相同
int cnt = 0;
//剩余树的数目
int vis[10000 + 10];
//用来判断树木有没有被访问过
int main(){
    L = read();
    M = read();//标准输入,不解释
    for(int i=1 ; i<=M; i++){
        //定义区间的头和尾
        int head = read();
        int tail = read();
        for(int j= head ; j <= tail; j++)
            if(vis[j] == 0)
                vis[j] = 1;//从这个区间的头和尾开始,将所有区间内的树标记为访问过
    }
    for(int i=0; i<= L;i++){
        if(vis[i] == 0)
            cnt++;//计算未被访问过的树的数目
    }
    cout<<cnt<<endl;
    return 0;
}
/*
500 3
150 300
100 200
470 471
============
298
*/

相关文章

  • 2020-09-01 校门外的树

    https://www.luogu.com.cn/problem/P1047

  • 031:校门外的树

    031:校门外的树 总时间限制: 1000ms 内存限制: 65536kB描述某校大门外长度为L的马路上有一排树,...

  • 0005-校门外的树

    问题描述 某校大门外长度为 L 的马路上有一排树,每两棵相邻的树之间的间隔都是 1 米。我们可以把马路看成一个数轴...

  • 1260: 校门外的树

    Time Limit: 1 SecMemory Limit: 128 MB Submit: 446Solved: ...

  • 玻璃门外的枸树

    这是一家电脑店,主人为了视觉的愉悦和期盼生意兴隆的念头从花鸟市场买来一盆发财树。发财树在主人的呵护下恣意地生长着,...

  • 园区的秋

    大门外 食堂路上 法桐树 法桐树二 银杏落叶

  • 打流感疫苗归来-成为Health hero

    2020-09-01 收到学校的邮件,要求打流感疫苗。 The T campus is having a flu ...

  • 诗者《迟暮黄昏》

    《迟暮黄昏》 我盯着门外那棵树 门外那棵树盯着夜空 它发呆,我也发呆 暮色还没有完全落去 而我想念那些有星光的日子...

  • jupyter notebook 用 onedrive实现多端同

    2020-09-01思路是把jupyter notebook的默认运行目录移动到onedrive中,参考https...

  • Flutter中const和final的区别

    // 同时赋值已经确定好的值const和final是没有区别的 const con = '2020-09-01'...

网友评论

      本文标题:2020-09-01 校门外的树

      本文链接:https://www.haomeiwen.com/subject/zgobsktx.html