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

洛谷P1047校门外的树题解

时间:2018-03-03 12:15:55      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:body   iostream   mes   for   pos   include   开始   sha   ios   

摘要:

此题是一个模拟题,但需要注意的一点就是它的树是从数轴的0开始,所以我们也要从0开始,这样才能实现代码。

代码:

#include<iostream>
using namespace std;
int s[100000];
int main()
{
  int l,m,x,y,d=0;
  cin>>l>>m;
  for(int i=0; i<=l; i++)
  s[i]=1;
  for(int i=0; i<m; i++)
  {
    cin>>x>>y;
    for(int i=x; i<=y; i++)
    s[i]=0;
  }
  for(int i=0; i<=l; i++)
  d+=s[i];
  cout<<d<<endl;
}

  

洛谷P1047校门外的树题解

标签:body   iostream   mes   for   pos   include   开始   sha   ios   

原文地址:https://www.cnblogs.com/liuwenyao/p/8496030.html

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