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

Codeforces Round #501 (Div. 3) A Points in Segments

时间:2018-08-16 10:44:23      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:一个   div   code   clu   std   覆盖   show   include   ++   

翻译

现在有一个数轴,上面会有\(M\)个点,标号为\(1\)\(N\),现在给你在数轴上的条\(N\)线段的起始与终止的点,问哪几个点没有被这样线段覆盖,从小到大输出。

思路

签到题目。感觉几乎和一道题一样:校门外的树,撞题是很尴尬。思路差不多,即为开一个数组,全部赋值为\(0\),输入的线段的时候,将其起点与终点的全部的点赋值为\(1\),最后跑一下看看那些为\(0\)的点就完事了。

Code

#include<iostream>
using namespace std;
int book[1001];//默认为0
int main()
{
    int n,k,t=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        for(int j=a;j<=b;j++)//标记线段的区间
            book[j]=1;
    }
    for(int i=1;i<=k;i++)
        if(book[i]==0)//0即为没有覆盖
            t++;
    cout<<t<<endl; 
    for(int i=1;i<=k;i++)
        if(book[i]==0)
            cout<<i<<" ";   
    return 0;
}

Codeforces Round #501 (Div. 3) A Points in Segments

标签:一个   div   code   clu   std   覆盖   show   include   ++   

原文地址:https://www.cnblogs.com/lyfoi/p/9485072.html

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