Fox and Box Accumulation CodeForces
来源:互联网 发布:君权级战列舰知乎 编辑:程序博客网 时间:2024/06/05 13:22
题意:有n个箱子,告诉你每个箱子上面可以容纳的箱子个数,问至少可以分成几堆箱子。
思路: wa 2了发,一直找不出bug, 我想有没有什么东西没特判的。想了很久,没想出来。 想了一个小时,突然想到一个样例,对于3 3 3 ,输出应该是1,而我输出是3,那么问题来了。sort后,对于数字小的,能放的我们应该尽量去放,尽量放的多,这样就尽可能让堆数少
#include <bits/stdc++.h>using namespace std;const int maxn=200;int a[maxn];bool vis[maxn];int n;void solve(int index){ int temp=a[index]; int cnt=1; for(int i=index+1;i<=n;i++) { if(vis[i]==false && cnt <= a[i]) { cnt ++; vis[i]=true; } } return ;}int main(void){ int cnt=0; memset(vis,false,sizeof(vis)); cin >> n; for(int i=1; i<=n; i++) scanf("%d",&a[i]); sort(a+1,a+1+n); for(int i=1;i<=n;i++) { if(vis[i]==false) solve(i),cnt++;; } cout << cnt << endl;}
通过这道题我会了什么?
1.发现这题无非是贪心。贪心无非就是为了求得最优的解,这和我们平时的思维是差不多的。
阅读全文
0 0
- codeforces Fox and Box Accumulation
- codeforces Fox and Box Accumulation
- Fox and Box Accumulation CodeForces
- [Codeforces] 389C - Fox and Box Accumulation
- CodeForces 388A Fox and Box Accumulation
- CodeForces 388A Fox and Box Accumulation
- codeforces-388A-Fox and Box Accumulation
- Fox and Box Accumulation
- A. Fox and Box Accumulation
- vj Fox and Box Accumulation
- Codeforces #228 (Div. 2)C. Fox and Box Accumulation
- Codeforces Round #228 (Div. 2)C. Fox and Box Accumulation
- Codeforces Round #228 (Div. 2)C. 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 贪心
- Linux进程间通信概述
- 避免Block的循环引用
- C语言:动态分配内存,malloc()与realloc()区别
- c# swagger 笔记二
- 最近项目有个需要,需要动态截取输入字符串中的某些特殊字符组,使用正则表达式可以完成。记下备用
- Fox and Box Accumulation CodeForces
- 公共耦合
- 中国剩余定理求解同余线性方程组—(互素和非互素的情况)
- Caffe-OpenCL在ubuntu16.04.2上的简要安装指南
- java线程池
- javascript如何查找字符中的回文串?
- Java Web开发技术(二)
- [树状数组]code[vs] 1082——线段树练习 3
- Qt加载动态库的步骤