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;
}

 

posted @ 2012-12-29 20:20  金海峰  阅读(231)  评论(0编辑  收藏  举报