[Codeforces] 389C - Fox and Box Accumulation
2014-02-04 08:53
316 查看
题意:有N个盒子,每个盒子上面可以放xi个盒子。问最少分几堆。
思路:xi从小到大贪心,最终得到最少几堆能放下,一开始我想的思路是xi从大到小贪心,后来验证思路错了。
思路:xi从小到大贪心,最终得到最少几堆能放下,一开始我想的思路是xi从大到小贪心,后来验证思路错了。
#include <stdio.h> #include <stdlib.h> int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int n, i, j, a[100], tmp, flag; while(~scanf("%d", &n)) { for(i = 0; i < n; i++) { scanf("%d", &a[i]); } qsort(a, n, sizeof(a[0]), cmp); for(i = flag = 0; i < n; i++) { if(a[i] != -1) { tmp = 1; for(j = i + 1; j < n; j++) { if(a[j] >= tmp && a[j] != -1) { tmp++; a[j] = -1; } } flag++; } } printf("%d\n", flag); } return 0; }
相关文章推荐
- Fox and Box Accumulation CodeForces - 388A
- 贪心-codeforces-388A-Fox and Box Accumulation
- codeforces-388A-Fox and Box Accumulation
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心
- A. Fox and Box Accumulation
- cf C. Fox and Box Accumulation
- Codeforces Round #228 (Div. 2)C. Fox and Box Accumulation
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
- cf228 div2 C. Fox and Box Accumulation(贪心, 二分)
- Codeforces Round #228 (Div. 2) C Fox and Box Accumulation(贪心)
- Fox and Box Accumulation
- A. Fox and Box Accumulation
- Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation
- Codeforces Round #228 (Div. 1)A. Fox and Box Accumulation(逆向思维)
- CF228C题Fox and Box Accumulation
- codeforces389 C. Fox and Box Accumulation【简单贪心】
- 【贪心+简单题】-CF-388A-A fox and box accumulation
- Codeforces #228 (Div. 2)C. Fox and Box Accumulation
- CF 388A:Fox and Box Accumulation