1 条题解
-
0
C :
#include <stdio.h> #include <string.h> int main(){ int m, s, c, i, j, k, number, tmp, flag, min, max, result, goods[256], notOccupied[256]; while (EOF != scanf("%d%d%d", &m, &s, &c)){ min = 256; max = 0; memset(goods, 0, sizeof(goods)); while (c--){ scanf("%d", &tmp); goods[tmp] = 1; if (tmp > max){ max = tmp; } if (tmp < min){ min = tmp; } } k = 0; tmp = 0; flag = 0; for (i = min; i <= max; i++){ if (goods[i]){ if (flag){ notOccupied[k++] = tmp; } tmp = 0; flag = 0; continue; } tmp++; flag = 1; } for (i = 0; i < k; i++){ for (j = i + 1; j < k; j++){ if (notOccupied[i] < notOccupied[j]){ tmp = notOccupied[i]; notOccupied[i] = notOccupied[j]; notOccupied[j] = tmp; } } } result = max - min + 1; for (i = 0; i < m - 1 && i < k; i++){ result -= notOccupied[i]; } printf("%d\n", result); } return 0; }
C++ :
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int V = 200 + 5; int m, s, c, len[V], ans[V]; int main() { int i, j; while(~scanf("%d%d%d", &m, &s, &c)) { for(i = 0; i < c; ++i) scanf("%d", &len[i]); sort(len, len + c); for(i = 1; i < c; ++i) ans[i - 1] = len[i] - len[i - 1] - 1; sort(ans, ans + c - 1); int L = len[c - 1] - len[0] + 1; while(--m && c--) L -= ans[c - 1]; printf("%d\n", L); } }
- 1
信息
- ID
- 1514
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者