Link

HDOJ - Problem - Moving Tables

易错点

  1. 桌子不一定从前往后搬,也可能从后往前搬,例如从 20 搬到 10 号位置,所以需要比较大小。

  2. 注意对题意的理解,例如 1 -> 3 和 4 -> 6 虽然数字上没有叠加区间,但在房间布局上是有叠加区间的,所以需要对房间数 +1 后 ÷2 来得到房间的“位置”。

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

KoreyLee
27 声望6 粉丝

Those who were seen dancing were thought to be insane by those who could not hear the music.


引用和评论

0 条评论