天天看點

貪心 hdu1050 Moving Tables

題意:從一個房間把桌子搬運到另一個房間,需要10分鐘,且中間的走廊在這10分鐘内不能被别人使用

現在有許多條桌子要搬送,問最少需要多少時間

很容易想到貪心,某個點,被區間覆寫的次數最多的,就是最長需要的時間

但是這題有陷阱,因為并沒有說明每次給的兩個數字,前一個會小于後一個

是以可能後前一個會大于後一個,是以在讀入的時候可能要交換左右的大小

#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<ctime>
#include<functional>
#include<algorithm>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int MX = 1e3 + 5;
const int INF = 0x3f3f3f3f;

int IN[MX], OUT[MX];

//,,這資料吓哭我了
int main() {
    //freopen("input.txt", "r", stdin);
    int T;
    scanf("%d", &T);
    while(T--) {
        int n;
        scanf("%d", &n);

        for(int i = 1; i <= n; i++) {
            int L, R;
            scanf("%d%d", &L, &R);
            IN[i] = (L + 1) / 2;
            OUT[i] = (R + 1) / 2;
            if(IN[i] > OUT[i]) swap(IN[i], OUT[i]);
        }
        sort(IN + 1, IN + 1 + n);
        sort(OUT + 1, OUT + 1 + n);

        int c1 = 1, c2 = 1, ans = 0, cnt = 0;
        for(int i = 1; i <= 200; i++) {
            while(c1 <= n && IN[c1] == i) {
                c1++;
                cnt++;
            }
            ans = max(ans, cnt);
            while(c2 <= n && OUT[c2] == i) {
                c2++;
                cnt--;
            }
        }
        printf("%d\n", ans * 10);
    }
    return 0;
}