Codeforces 388A Fox and Box Accumulation(贪心)
来源:互联网 发布:淘宝网上的汽车能买吗 编辑:程序博客网 时间:2024/06/05 15:26
题意:给出n个箱子,每个箱子都有一个力量值Vi,代表能支撑Vi个箱子,求能把这些箱子摆成的最少的堆数.
思路:刚开始想着从大到小排序来做,从第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;}
0 0
- Codeforces 388A Fox and Box Accumulation(贪心)
- Codeforces 388A Fox and Box Accumulation(贪心)
- 贪心-codeforces-388A-Fox and Box Accumulation
- CodeForces 388A Fox and Box Accumulation(贪心)
- CodeForces 388A Fox and Box Accumulation 贪心
- CodeForces 388A Fox and Box Accumulation
- CodeForces 388A Fox and Box Accumulation
- codeforces-388A-Fox and Box Accumulation
- CodeForces 388A Fox and Box Accumulation (模拟)
- CF 388A:Fox and Box Accumulation
- codeforces Fox and Box Accumulation
- codeforces Fox and Box Accumulation
- Fox and Box Accumulation CodeForces
- A. Fox and Box Accumulation
- Codeforces 389C Fox and Box Accumulation【贪心】
- Codeforces Round #228 (Div. 1) 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
- Try to use "twisted.enterprise.adbapi" accessing database nonblockingly in Twisted (failed)
- Linux文件共享(五)——线程共享文件
- OpenCV 自带例程总结
- Java多线程实现多个客户端同时与服务器进行TCP通信
- 摘录TCP,ttl计算更新方法
- Codeforces 388A Fox and Box Accumulation(贪心)
- Linux-2.6.32.2内核在mini2440上的移植(四)---根文件系统制作(1)
- leetCode刷题笔记(六)
- bzoj2743 HEOI2012采花 离线预处理
- C语言文件操作函数大全
- Jquery.cookie使用
- Socks代理反弹突破内网
- 第五周-基本控制语句
- JAVA 回调实例