洛谷 Atcoder 题解 AT2585 【Colorful Leaderboard】

目测 普及/提高- 难度。

思路

将 9 种可能的等级存储在数组里,则 min 值为分数为 0 ~ 3199 的颜色种类个数,max 值为 min 值加上分数 >3200 的人数。

特判

若分数为 0 ~ 3199 的颜色种类个数为 0,分数 >3200 的人数大于 1,则min 值为 1,max 值为分数 >3200 的人数

代码

#include <stdio.h>

int getBlock(int rating)
{
    if (rating < 400) return 1;
    else if (rating < 800) return 2;
    else if (rating < 1200) return 3;
    else if (rating < 1600) return 4;
    else if (rating < 2000) return 5;
    else if (rating < 2400) return 6;
    else if (rating < 2800) return 7;
    else if (rating < 3200) return 8;
    else return 0;
}

int min(int a, int b)
{
    if (a < b)
        return a;
    return b;
}

int max(int a, int b)
{
    if (a > b)
        return a;
    return b;
}

int main()
{
    int n, t, block[9] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        block[getBlock(t)]++;
    }
    int res = 0;
    for (int i = 1; i <= 8; i++) {
        if (block[i] != 0) res++;
    }
    if (res != 0)
        printf("%d %d", res, res + block[0]);
    else 
        printf("%d %d", 1, block[0]);
}
posted @ 2018-11-02 14:13  航空信奥  阅读(267)  评论(0编辑  收藏  举报