【瞎搞】HDU 5124 lines

本文探讨了如何通过编程实现计算给定n条线段覆盖点次数最多的条数,采用C++语言实现,涉及算法排序和数据结构应用。

点击打开链接

题意:给出n条线段求覆盖点 次数最多的条数。


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define cler(arr, val)    memset(arr, val, sizeof(arr))
#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define IN   freopen ("in.txt" , "r" , stdin);
#define OUT  freopen ("out.txt" , "w" , stdout);
typedef long long  LL;
const int MAXN = 111011;
const int MAXM = 610;
const int INF = 0x3f3f3f3f;
const LL mod = 2147483647;
const double eps= 1e-8;
const double pi=acos(-1.0);
#define lson l,m, rt<<1
#define rson m+1,r,rt<<1|1int len,dig[66];
struct node
{
    int p,value;
}po[MAXN<<1];
bool cmp(node a,node b)
{
    if(a.p==b.p)
        return a.value<b.value;
    return a.p<b.p;
}
int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&po[i*2].p,&po[i*2+1].p);
            po[i*2+1].p++;
            po[i*2].value=1;
            po[i*2+1].value=-1;
        }
        int ans=0,mx=0;
        sort(po,po+2*n,cmp);
        for(int i=0;i<2*n;i++)
        {
            ans+=po[i].value;
            mx=max(ans,mx);
        }
        cout<<mx<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值