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 ...
随机推荐
- Linux USB驱动框架分析(2)【转】
转自:http://blog.chinaunix.net/uid-23046336-id-3243543.html 看了http://blog.chinaunix.net/uid-11848011 ...
- nginx 的多域名多https转发设置方法【转】
version: 1.1(fixed) 修正一些错误基本环境:/etc/nginx/nginx.conf #保持/etc/nginx/ssl/ #ssl认证文件/etc/nginx/site-a ...
- 畸形的 dockerfile中的COPY命令-
dockerfile中的COPY是指COPY 指定目录的“子级目录”下所有的目录和文件,到指定目录中,这个shell中的cp命令大相径庭,使得很多人纳闷,怎么cpy过去的文件不是自己想要的
- python3 切换工作文件夹
python3 默认的工作文件夹在Python安装路径下.如下为查看工作文件夹路径: >>> import os >>> os.getcwd() 'D:\\Work ...
- ASP防XSS代码
原作是在GitHub上,基于Node.js所写.但是..ASP的JS引擎跟V8又有些不同..于是,嗯.. <% Function AntiXSS_VbsTrim(s) AntiXSS_VbsTr ...
- python操作mysql(pymysql + sqlalchemy)
pymysql pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同. 下载安装 pip3 install pymysql 使用操作 1.执行sql #!/usr/bi ...
- pycharm tornado 项目 配置
ycharm 配置tornado项目 使得能够像django项目一样运行
- IIS 启用https
参考:http://www.cnblogs.com/dudu/p/iis_https_ca.html
- 关闭linux退格键和vi发出的嘟嘟声
以root用户登录,然后请安下面方法进行操作: 在命令行下执行:echo "rmmod pcspkr" >> /etc/rc.d/rc.local
- CSS — 贝塞尔曲线(cubic-bezier)
cubic-bezier 又称三次贝塞尔,主要是为 animation 生成速度曲线的函数,规定是 cubic-bezier(<x1>, <y1>, <x2>, & ...