Codeforces 388A Fox and Box Accumulation(贪心)
2014-04-07 10:46
211 查看
题意:给出n个箱子,每个箱子都有一个力量值Vi,代表能支撑Vi个箱子,求能把这些箱子摆成的最少的堆数.
思路:刚开始想着从大到小排序来做,从第i个箱子开始能放上去的就放上去,题目的最后一个数据很好的否定了这种做法.
应该从小到大排序,记录当前堆的个数,能否把当前堆放到下一个箱子上,不能放就作为一堆.
思路:刚开始想着从大到小排序来做,从第i个箱子开始能放上去的就放上去,题目的最后一个数据很好的否定了这种做法.
应该从小到大排序,记录当前堆的个数,能否把当前堆放到下一个箱子上,不能放就作为一堆.
#include <cstdio> #include <functional> #include <algorithm> using namespace std; const int MAX = 101; int boxes[MAX]; bool vis[MAX]; int main(int argc, char const *argv[]){ int n, ans = 0; scanf("%d", &n); for(int i = 0; i < n; ++i){ scanf("%d", &boxes[i]); } sort(boxes, boxes + n); for(int i = 0; i < n; ++i){ if(vis[i])continue; int cnt = 1; for(int j = i + 1; j < n; ++j){ if(!vis[j] && boxes[j] >= cnt){ cnt++; vis[j] = true; } } ans++; } printf("%d\n", ans); return 0; }
相关文章推荐
- 【Codeforces】-597B-Restaurant(贪心)
- codeforces 496E Distributing Parts(贪心)
- Codeforces 534D Handshakes【贪心】
- [杂题 贪心] Codeforces 808E. Selling Souvenirs
- codeforces 479C Exams 排序贪心
- Codeforces 680D Bear and Tower of Cubesp【贪心+Dfs】有点难度啊T T
- Codeforces 521A DNA Alignment【贪心+思维】
- Codeforces-792E Colored Balls(贪心/数学)
- codeforces 416C C. Booking System(贪心)
- CodeForces - 730A 贪心+模拟
- Codeforces 492B Vanya and Lanterns【贪心】
- Codeforces 416C Booking System(贪心)
- codeforces 509C Sums of Digits (贪心对位操作)
- Codeforces 583 DIV2 Robot's Task 贪心
- 【CodeForces - 849】C From Y to Y 【思维+构造+贪心】
- Codeforces 556D Case of Fugitive【排序+贪心】
- CodeForces 128D Numbers [想法题/贪心]
- CodeForces - 527D Clique Problem (图,贪心)
- codeforces 733C Epidemic in Monstropolis 贪心
- codeforces - 735B - Urbanization(贪心)