codeforces A. Fox and Box Accumulation 解题报告
题目链接:http://codeforces.com/problemset/problem/388/A
题目意思:有 n 个 boxes,每个box 有相同的 size 和 weight,但是strength 有可能不同。strength的数值表示该box的上面只能放strength 个 boxes,直到放不下,这样就成了一个pile。
问如何叠放使得pile 的个数最少。
一开始从最底层放置考虑,于是越想越复杂.....
可以从最高层来开始,那么放在最上面的box的strength最小可以为0,但是stength为0的box在每个pile中最多只可以放一个(0代表这个box上面不能再放任何的box!),接着它的下一层,strength最小都要为1,表示在上面可以放一个(也就是0 strength的box),紧跟着的下一层strength最小为2,.....直到处理最后的一层,于是第一个pile就构成了,而且是最优的。接着下一个pile的构成同上,但要用一个标记vis,防止重复使用第一个pile用过的box。这个过程持续到所有box都构成pile为止。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
int a[maxn], vis[maxn]; int main()
{
int i, n;
while (scanf("%d", &n) != EOF)
{
for (i = ; i < n; i++)
scanf("%d", &a[i]);
memset(vis ,, sizeof(vis));
sort(a, a+n);
int ans = ;
int tmp, tol = n;
while (tol)
{
tmp = ;
for (i = ; i < n; i++)
{
if (tmp <= a[i] && !vis[i])
{
vis[i] = ;
tmp++; // 下一层需要的最小strength
tol--; // box用了一个
}
}
ans++; // 一个pile建立
}
printf("%d\n", ans);
}
return ;
}
codeforces A. Fox and Box Accumulation 解题报告的更多相关文章
- CodeForces 388A Fox and Box Accumulation (模拟)
A. Fox and Box Accumulation time limit per test:1 second memory limit per test:256 megabytes Fox Cie ...
- Codeforces 388A - Fox and Box Accumulation
388A - Fox and Box Accumulation 思路: 从小到大贪心模拟. 代码: #include<bits/stdc++.h> using namespace std; ...
- codeforces 510B. Fox And Two Dots 解题报告
题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...
- 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. 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: 很简单的贪心,比赛的时候没想出来.... ...
- A. Fox and Box Accumulation
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- codeforces B. Eugeny and Play List 解题报告
题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...
随机推荐
- BZOJ1009GT考试 DP + KMP + 矩陣快速冪
@[DP, KMP, 矩陣快速冪] Description 阿申准备报名参加GT考试,准考证号为\(N\)位数\(X_1 X_2 .. X_n(0 <= X_i <= 9)\),他不希望准 ...
- 2.【nuxt起步】-初始化创建nuxt项目
1. 脚手架初始化: vue init nuxt-community/starter-template NuxtMyms 2.输入项目相关信息 3.切换到项目目录下 安装依赖 Cd nuxtmyms ...
- System::String *,char*,string 等的类型转换 [转]
在VC 的编程中,经常会用到各种类型的转换,在MFC中textbox等控件得到的返回类型是System::String *,而写入的文件要求是 const char *类型的,下面介绍一些转换的方法: ...
- 【Java编程】Java在dos窗体编译与运行的批处理
近期在Java编程过程中,常常使用到dos窗体对程序进行编译与执行. 可是不方便之处在于每次都要输入命令进入将要编译的程序的文件夹(事实上也有简单的方法,在文章末尾给出).于是编写了一个配置文件,能够 ...
- 零基础学python-3.7 还有一个程序 python读写文本
今天我们引入另外一个程序,文件的读写 我们先把简单的程序代码贴上.然后通过我们多次的改进.希望最后可以变成一个简单的文本编辑器 以下是我们最简单的代码: 'crudfile--读写文件' def re ...
- mysql手动停止无响应查询方法
http://www.chenweionline.cn/archives/61.htm
- 8款精美的HTML5图片动画分享
From:http://geek.csdn.net/news/detail/196250 HTML5结合jQuery可以让网页图片变得更加绚丽多彩,比如实现一些图片3D切换.CSS3动画绘制以及各种图 ...
- 【C语言】求两个数中不同的位的个数
//求两个数中不同的位的个数 #include <stdio.h> int count_different(int a, int b) { int count = 0; int c = a ...
- Oracle 【to_number】【instr】
需求:对一个包含数字的字符串排序 search后参考了 http://www.cnblogs.com/m-cnblogs/archive/2012/03/30/2425938.html 截屏: (用 ...
- android中的MD5、Base64、DES/3DES/ADES加解密
MD5摘要算法: <span style="font-size:18px;">主要代码: String s = edit.getText().toString(); i ...