zoukankan      html  css  js  c++  java
  • zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors

    Time Limit: 1 Sec  Memory Limit: 256 MB

    题目连接

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610

    Description

    Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.

    Your task is counting the segments of different colors you can see at last.

    Input

    The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.

    Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:

    x1 x2 c

    x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.

    All the numbers are in the range [0, 8000], and they are all integers.

    Input may contain several data set, process to the end of file.

    Output

    Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.

    If some color can't be seen, you shouldn't print it.

    Print a blank line after every dataset.

     

    Sample Input

    5
    0 4 4
    0 3 1
    3 4 2
    0 2 2
    0 2 3
    4
    0 1 1
    3 4 1
    1 3 2
    1 3 1
    6
    0 1 0
    1 2 1
    2 3 1
    1 2 0
    2 3 0
    1 2 1

    Sample Output

    1 1
    2 1
    3 1

    1 1

    0 2
    1 1

     

     

    HINT

    题意

    涂墙壁,然后问你最后能看见多少种颜色

    题解:

    数据范围太小,暴力可过,和贴海报那道题是一样的

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    //**************************************************************************************
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    
    int cnt[18001];
    int color[18001];
    int main()
    {
        int n;
        int a,b,c;
        while(scanf("%d",&n)!=EOF)
        {
            memset(cnt,0,sizeof(cnt));
            memset(color,0,sizeof(color));
            int ma=0;
            for(int i=0;i<n;i++)
            {
                a=read(),b=read(),c=read();
                for(int j=a;j<b;j++)
                    color[j]=c+1;
                ma=max(ma,b);
            }
            for(int i=0;i<=ma;i++)
            {
                while(i!=0&&color[i]&&color[i]==color[i-1])
                    i++;
                if(color[i])
                    cnt[color[i]-1]++;
            }
            for(int i=0;i<=8001;i++)
                if(cnt[i])
                    printf("%d %d
    ",i,cnt[i]);
            puts("");
        }
    }
  • 相关阅读:
    BZOJ4889: [TJOI2017]不勤劳的图书管理员
    BZOJ3932: [CQOI2015]任务查询系统
    BZOJ1926: [Sdoi2010]粟粟的书架
    POJ 3281 Dining(网络流-拆点)
    POJ 1273 Drainage Ditches(网络流-最大流)
    POJ 1325 Machine schedine (二分图-最小点覆盖数=最大匹配边数)
    HDU 1281 棋盘游戏
    HDU2255 奔小康赚小钱钱(二分图-最大带权匹配)
    HDU 2444 The Accomodation of Students (二分图存在的判定以及最大匹配数)
    POJ 3660 cow contest (Folyed 求传递闭包)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4447657.html
Copyright © 2011-2022 走看看