[Codeforces] 1015A. Points in Segments

題目URL:http://codeforces.com/contest/1015/problem/A
這題我很暴力標點,但之後被某位電神指點說這題其實用b-a+1去標記a點,走O(N)就結束了。嘛......反正我也懶得改了XD~


#include<bits/stdc++.h>
using namespace std;
int a,b,boo[1005],str[1005],n,m,total=0;
main()
{
    cin >> n >> m;
    for(int i=0;i<n;i++)
    {
        cin >>  a >> b;
        for(int j=a;j<=b;j++)
        boo[j]++;
    }
    int flag=0;
    for(int i=1;i<=m;i++)
    {
        if(boo[i]==0)
        {
            total++;
            str[flag++]=i;
        }
    }
    cout << total <<endl;
    for(int i=0;i<flag;i++)
        cout << str[i] << " ";
    cout << endl;
    return 0;
}

留言

這個網誌中的熱門文章

[ZJ] b229: TOI 2009 第一題:路徑問題

交大資工(APCS組)(面試&心得)

滿是挫傷的ION CAMP