ACM — Moving Tables

Link

HDOJ - Problem - Moving Tablesphp

易錯點

  1. 桌子不必定從前日後搬,也可能從後往前搬,例如從 20 搬到 10 號位置,因此須要比較大小。佈局

  2. 注意對題意的理解,例如 1 -> 3 和 4 -> 6 雖然數字上沒有疊加區間,但在房間佈局上是有疊加區間的,因此須要對房間數 +1 後 ÷2 來獲得房間的「位置」。code

Code

#include <stdio.h>
#include <cstring>

int main() {
    int t, n, a, b, max, rooms[205];
    scanf("%d", &t);
    for (int i = 0; i < t; ++i) {
        memset(rooms, 0, sizeof(rooms));
        scanf("%d", &n);
        for (int j = 0; j < n; ++j) {
            scanf("%d%d", &a, &b);
            if (a > b) {
                int tmp = b;
                b = a, a = tmp;
            }
            for (int k = (a + 1) / 2; k <= (b + 1) / 2; ++k)
                rooms[k]++;
        }
        max = rooms[1];
        for (int l = 2; l <= 200; ++l) {
            if (rooms[l] > max)
                max = rooms[l];
        }
        printf("%d\n", max * 10);
    }
    return 0;
}
相關文章
相關標籤/搜索