Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心
A. Fox and Box Accumulation
题目连接:
http://codeforces.com/contest/388/problem/A
Description
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100).
Output
Output a single integer — the minimal possible number of piles.
Sample Input
3
0 0 10
Sample Output
2
Hint
题意
有n个箱子,现在对于每一个箱子告诉你这个箱子的上面最多放多少个箱子
现在你需要使得箱子的列数最小,请问是多少
题解:
从表象来说,感觉像一个多背包问题,但实质上是不是的
这个东西显然是可以贪心的,因为这个箱子你用还是不用,对下一个用啥是没有影响的
所以直接贪心就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int vis[maxn],ans;
int a[maxn];
int main()
{
int n;
scanf("%d",&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++)
{
int pre = -1;
for(int j=i;j<=n;j++)
{
if(vis[j])continue;
if(a[j]>pre)
{
vis[j]=1;
pre++;
}
}
if(pre!=-1)ans++;
}
cout<<ans<<endl;
}
Codeforces Round #228 (Div. 1) A. Fox and Box Accumulation 贪心的更多相关文章
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation
C. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)
题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...
- Codeforces Round #228 (Div. 1) C. Fox and Card Game 博弈
C. Fox and Card Game 题目连接: http://codeforces.com/contest/388/problem/C Description Fox Ciel is playi ...
- Codeforces Round #228 (Div. 1) B. Fox and Minimal path 构造
B. Fox and Minimal path 题目连接: http://codeforces.com/contest/388/problem/B Description Fox Ciel wants ...
- Codeforces Round #228 (Div. 1) 388B Fox and Minimal path
链接:http://codeforces.com/problemset/problem/388/B [题意] 给出一个整数K,构造出刚好含有K条从1到2的最短路的图. [分析] 由于是要自己构造图,当 ...
- Codeforces Round #228 (Div. 2) B. Fox and Cross
#include <iostream> #include <string> #include <vector> #include <algorithm> ...
- Codeforces Round #228 (Div. 2) A. Fox and Number Game
#include <iostream> #include <algorithm> #include <vector> #include <numeric> ...
- Codeforces Round #228 (Div. 2)
做codeforces以来题目最水的一次 A题: Fox and Number Game 题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值 sol: 简单数论题目,直接求所有 ...
- Codeforces Round #228 (Div. 1) A
A. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...
随机推荐
- sqlserver中一些常用的函数总结
去掉空格方面 LTRIM('内容'):去掉字符串左边的空格 RTRIM('内容'):去掉右边的空格 LTRIM(RTRIM('内容')):去掉字符串左边和右边的空格 REPLACE(‘内容’,' ', ...
- linux java配置
1.java配置 配置环境变量在/etc/profile下增加# set Java environmentJAVA_HOME=/usr/share/jdk1.6.0_43PATH=$JAVA_HOME ...
- No.18 selenium学习之路之批量执行测试用例
diascover方法,加载所有测试用例 1.discover方法里面有三个参数: -case_dir:测试用例的目录 -pattern:这个是匹配脚本名称的规则,test*.py意思是匹配test开 ...
- git —— pycharm+git管理/编辑项目
pycharm+git 管理/编辑项目 一.pycharm中配置github 二.配置git 并不是配置了GitHub就可以的.还需要配置一下Git 前提是本地中已经安装了git 三.把本地项目上传 ...
- CNN细节
1.各层作用 输入层 输入层是整个神经网络的输入,一般代表的是图片的像素矩阵(一般为三维矩阵,即像素x像素x通道) 卷积层 每一层卷积都会提取数据特征,再经过组合和抽象形成更高阶的特征. 池化层 保留 ...
- webpack性能优化-实战
题外话:年初项目重构上线,项目技术栈使用vue+webpack,测试执行整个打包流程需要10分钟,同时又因涉及三个渠道,部署好环境就需半个小时,这严重延误了上线进度,因此提高webpack构建效率,成 ...
- PHP性能调优---php-fpm中启用慢日志配置(用于检测执行较慢的PHP脚本)
虽然通过nginx accesslog可以记录用户访问某个接口或者网页所消耗的时间,但是不能清晰地追踪到具体哪个位置或者说函数慢,所以通过php-fpm慢日志,slowlog设置可以让我们很好的看见哪 ...
- Android 客户端 okhttp3 与服务器之间的双向验证
[原文]https://blog.csdn.net/leng_wen_rou/article/details/58596142 本篇是Android 客户端基于okhttp3的网络框架 和后台服务器之 ...
- Gitlab Webhooks, External Services, and API(一)
一. 和外部服务进行集成 Gitlab支持和不同的外部服务进行集成,比如可以和聊天工具,Slack或者Campfire进行集成,或者和项目管理工具进行集成.如Assembla或者Pivotal Tra ...
- poj1182 食物链(带权并查集)
题目链接 http://poj.org/problem?id=1182 思路 前面做的带权并查集的权值记录该结点与其父结点是否是同一类,只有两种取值情况(0,1),在这题中某结点a和其父结点b的取值共 ...