码迷,mamicode.com
首页 > 其他好文 > 详细

luogu 1047

时间:2018-01-24 13:55:33      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:区域   bsp   for   color   turn   include   ++   main   col   

差分。

设a[i]为这个点被多少个区域包含。

设f[i]为a[i]-a[i-1]。

于是每次读入一个区间[u,v]就把f[u]++,f[v+1]--。

每次计算前加上f[i]就是a[i]了。

只有当a[i]=0时这棵树才没有被砍掉。

#include"cstdio"
#include"cctype"
int read()
{
    int c,x=0; while(!isdigit(c=getchar()));
    while(x=x*10+c-0,isdigit(c=getchar()));
    return x;
}
int f[10002];
int main()
{
    int l=read(),m=read(),now=0,ans=0;
    while(m--)
    {
        f[read()]++;
        f[read()+1]--;
    }
    for(int i=0; i<=l; i++)
    {
        now+=f[i];
        ans+=!now;
    }
    printf("%d",ans);
    return 0;
}

 

luogu 1047

标签:区域   bsp   for   color   turn   include   ++   main   col   

原文地址:https://www.cnblogs.com/TrassBlose/p/8341126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!