洛谷 Atcoder 題解 AT2585 【Colorful Leaderboard】
阿新 • • 發佈:2018-11-02
目測 普及/提高- 難度。
思路
將 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]); }