poj1083

线段覆盖,注意从右往左挪的情况

View Code
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define room_num 400
#define maxn 205

struct Elem
{
    bool start;
    int pos;
}elem[maxn];

int n;
int elem_cnt;

bool operator < (const Elem &a, const Elem &b)
{
    if (a.pos == b.pos)
        return a.start;
    return a.pos < b.pos;
}

void add(int a, bool b)
{
    elem[elem_cnt].pos = a;
    elem[elem_cnt].start = b;
    elem_cnt++;
}

void input()
{
    elem_cnt = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        if (a > b)
            swap(a, b);
        add((a + 1) / 2, true);
        add((b + 1) / 2, false);
    }
}

void work()
{
    int ans = 0;
    int temp = 0;
    for (int i = 0; i < elem_cnt; i++)
    {
        if (elem[i].start)
            temp++;
        else
            temp--;
        ans = max(ans, temp);
    }
    printf("%d\n", ans * 10);
}

int main()
{
    //freopen("t.txt", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--)
    {
        input();
        sort(elem, elem + elem_cnt);
        work();
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/rainydays/archive/2012/12/29/2839226.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值