zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    <O(n),O(1)>的LCA
    hdu6110
    ACM模板
    prufer编码
    UvaLive6893_The_Big_Painting
    HDU5669
    Codeforces786B
    二分图部分总结
    Git简介和Windows下安装步骤
    笔记本电脑插入耳机后无法使用解决办法
  • 原文地址:https://www.cnblogs.com/rainydays/p/2839226.html
Copyright © 2011-2022 走看看