zoukankan      html  css  js  c++  java
  • lines-HDU5124(区间处理 +离散化)

    Problem Description
    John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A.
     
    Input
    The first line contains a single integer T(1T100)(the data for N>100 less than 11 cases),indicating the number of test cases.
    Each test case begins with an integer N(1N105),indicating the number of lines.
    Next N lines contains two integers Xi and Yi(1XiYi109),describing a line.
     
    Output
    For each case, output an integer means how many lines cover A.
     
    Sample Input
    2 5 1 2 2 2 2 4 3 4 5 1000 5 1 1 2 2 3 3 4 4 5 5
     
    Sample Output
    3 1
     
     
    题目大意:
    给你几个区间,然后给这区间间的点染色
    求最染色最多的点 染了多少色
     
    分析:
     
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include<iostream>
    #include<string.h>
    #include<algorithm>
    #include<vector>
    using namespace std;
    #define N 1100000
    
    struct node
    {
        int x,y;
    }a[N];
    int f[N],p[N];
    
    int main()
    {
        int T,n,i;
        scanf("%d",&T);
        while(T--)
        {
            int k=0;
            memset(a,0,sizeof(a));
            memset(f,0,sizeof(f));
            memset(p,0,sizeof(p));
            scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                scanf("%d %d",&a[i].x,&a[i].y);
                p[k++]=a[i].x;
                p[k++]=a[i].y;
            }
            sort(p,p+k);
            int len=unique(p,p+k)-p;
            int Max=0;
            for(i=0;i<n;i++)
            {
                int u=lower_bound(p,p+len,a[i].x)-p;
                int v=lower_bound(p,p+len,a[i].y)-p;
                f[u]++;
                f[v+1]--;
                Max=max(Max,v+1);
            }
            int ans=0,b=0;
            for(i=0;i<=Max;i++)
            {
                ans+=f[i];
                b=max(b,ans);
            }
            printf("%d
    ",b);
        }
        return 0;
    }
  • 相关阅读:
    svn使用
    canvas入门-3渐变方法
    canvas入门-2路径、文字
    canvas入门-1三种填充方式、渐变、模式
    jquery extend的使用
    angular入门-ngOptions
    jquery-EasyUI---panel面板的用法
    jquery-EasyUI---tooltip提示框的使用
    jquery-EasyUI---progressbar进度条的的使用
    jquery-EasyUI---searchbox搜索框的用法
  • 原文地址:https://www.cnblogs.com/linliu/p/4975356.html
Copyright © 2011-2022 走看看