Fox and Box Accumulation CodeForces - 388A
2017-07-24 14:44
405 查看
题意:有n个箱子,告诉你每个箱子上面可以容纳的箱子个数,问至少可以分成几堆箱子。
思路: wa 2了发,一直找不出bug, 我想有没有什么东西没特判的。想了很久,没想出来。 想了一个小时,突然想到一个样例,对于3 3 3 ,输出应该是1,而我输出是3,那么问题来了。sort后,对于数字小的,能放的我们应该尽量去放,尽量放的多,这样就尽可能让堆数少
通过这道题我会了什么?
1.发现这题无非是贪心。贪心无非就是为了求得最优的解,这和我们平时的思维是差不多的。
思路: 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.发现这题无非是贪心。贪心无非就是为了求得最优的解,这和我们平时的思维是差不多的。
相关文章推荐
- codeforces-388A-Fox and Box Accumulation
- 贪心-codeforces-388A-Fox and Box Accumulation
- 【贪心+简单题】-CF-388A-A fox and box accumulation
- CF 388A:Fox and Box Accumulation
- [Codeforces] 389C - Fox and Box Accumulation
- A. 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. 1) A. Fox and Box Accumulation
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
- codeforces389 C. Fox and Box Accumulation【简单贪心】
- Codeforces Round #228 (Div. 2) C Fox and Box Accumulation(贪心)
- cf C. Fox and Box Accumulation
- cf228 div2 C. Fox and Box Accumulation(贪心, 二分)
- Fox and Box Accumulation
- A. Fox and Box Accumulation
- CF228C题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 #228 (Div. 2)C. Fox and Box Accumulation