Codeforces Round #228 (Div. 1) A
1 second
256 megabytes
standard input
standard output
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 thanxi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100).
Output a single integer — the minimal possible number of piles.
3
0 0 10
2
5
0 1 2 3 4
1
4
0 0 0 0
4
9
0 1 0 2 0 1 1 2 10
3 二分pile的个数。
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <set>
using namespace std;
typedef long long LL ; int x[] , n ;
int pile[][] ;
int judge(int Len){
memset(pile,-,sizeof(pile)) ;
int row = n/Len , k = , i ,j;
for(i = ; i <= n/Len ; i++)
for(j = ; j <= Len ; j++)
pile[i][j] = x[k++] ;
if(n % Len){
row++ ;
j = ;
while(k < n)
pile[row][j++] = x[k++] ;
}
for(i = ; i <= Len ; i++){
for(j = ; j <= row ; j++){
if(pile[j][i] != - &&pile[j][i] < j - )
return ;
}
}
return ;
} int b_s(){
int L = ,R = n ,mid ,ans;
while(L <= R){
mid = (L + R)>> ;
if(judge(mid)){
ans = mid ;
R = mid - ;
}
else
L = mid + ;
}
return ans ;
} int main(){
int i ;
cin>>n ;
for(i = ; i < n ; i++)
cin>>x[i] ;
sort(x , x + n) ;
cout<<b_s()<<endl ;
return ;
}
Codeforces Round #228 (Div. 1) A的更多相关文章
- 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)
今天学长给我们挂了一套Div.1的题,难受,好难啊. Problem A: 题目大意:给你n个数字,让你叠成n堆,每个数字上面的数的个数不能超过这个数,如 3 上面最多放三个数字 问你,最少能放几堆. ...
- 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) A. Fox and Box Accumulation 贪心
A. Fox and Box Accumulation 题目连接: http://codeforces.com/contest/388/problem/A Description Fox Ciel h ...
- 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)
做codeforces以来题目最水的一次 A题: Fox and Number Game 题意:就是用一堆数字来回减,直到减到最小值为止,再把所有最小值加,求这个值 sol: 简单数论题目,直接求所有 ...
- 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. 1) B
B. Fox and Minimal path time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- opencv基本的数据结构(转)
DataType : 将C++数据类型转换为对应的opencv数据类型 enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, ...
- 删除IE 下输入后的清除小叉叉
input::-ms-clear { display: none; } css去掉ie10,11中input[type="text"]后面的X图标 input[type=" ...
- 网站优化之Asp.Net篇<一>
一>禁用viewstate. 二>禁用动态编译.访问一个Aspx文件时 会编译为一个新的类放在C盘Asp.net临时文件夹下.下次请求不会再编译,会把先前的编译结果返回. 任何对Asp.n ...
- android 定时器AlarmManager
1.android中通常是使用AlarmManager来定时启动一个单次或重复多次操作的.具体的说就是我们通过AlarmManager设定一个时间和注册一个intent到系统中,然后在该时间到来时,系 ...
- 2014年5月份第1周51Aspx源码发布详情
郑州某高校学生考评系统源码 2014-5-5 [VS2008]功能介绍: 1.用户角色有部主任.教师.学生等. 2.可添加班级考评项目.学生考评项目. 3.可指定学生对班级.学生某考评项 ...
- Android中build target,minSdkVersion,targetSdkVersion,maxSdkVersion概念区分 (转载)
本文参考了谷歌开发者文档:http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#provisional 如果 ...
- 期望DP
BZOJ 1415 #include <iostream> #include <cstring> #include <algorithm> #include < ...
- Binary Tree Inorder Traversal -- LeetCode 94
Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...
- Flask-DebugToolbar
This extension adds a toolbar overlay to Flask applications containing useful information for debugg ...
- VC++ 文件系统
using namespace System; using namespace System::IO; void ShowHelpMsg(){ Console::WriteLine(L"本程 ...