题目链接: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 解题报告的更多相关文章

  1. 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 ...

  2. Codeforces 388A - Fox and Box Accumulation

    388A - Fox and Box Accumulation 思路: 从小到大贪心模拟. 代码: #include<bits/stdc++.h> using namespace std; ...

  3. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)

    题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...

  7. A. Fox and Box Accumulation

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  8. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  9. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

随机推荐

  1. Java创建和解析Json数据方法(五)——Google Gson包的使用

    (五)Google Gson包的使用 1.简介 Gson包中,使用最多的是Gson类的toJson()和fromJson()方法:         ①toJson():将java对象转化为json数据 ...

  2. 品质与合身 无须昂贵 | Tailorwoods在线男装定制

    品质与合身 无须昂贵 | Tailorwoods在线男装定制 北京市朝阳区姚家园北一路八月照相馆2F

  3. 使用和不使用navigationbar分别处理显示和返回页面

    不使用navigationbar的情况下 AnnounceViewController *pushView = [[AnnounceViewController alloc]init];pushVie ...

  4. 【swagger】2.swagger提供开发者文档--返回统一格式篇【spring mvc】【spring boot】

    接着上一篇来说, 不管正常返回结果还是后台出现异常,应该返回给前台统一的响应格式. 所以这一篇就为了应对解决这个问题. ======================================== ...

  5. 进程间通信IPC、LPC、RPC

    进程间通信(IPC,Inter-Process Communication),指至少两个进程或线程间传送数据或信号的一些技术或方法.进程是计算机系统分配资源的最小单位.每个进程都有自己的一部分独立的系 ...

  6. 网页Tab控件

    网页Tab控件 找到:http://www.open-open.com/ajax/2_Tabs.htm 页面,查看了若干Tab控件, 找到了:http://www.open-open.com/ajax ...

  7. java中finalkeyword

    在java中有3个地方须要用finalkeyword: 1.假设一个不希望被继承,那么用final来修饰这个类 2.假设一个方法不须要被重写.那么这种方法用final来修饰 3.假设一个变量的值不希望 ...

  8. SwitchyOmega 代理设置

    1.SwitchyOmega官网 https://www.switchyomega.com/ 2.下载插件 https://www.switchyomega.com/download.html 3.配 ...

  9. C++11 并发指南四(<future> 详解一 std::promise 介绍)(转)

    前面两讲<C++11 并发指南二(std::thread 详解)>,<C++11 并发指南三(std::mutex 详解)>分别介绍了 std::thread 和 std::m ...

  10. Atitit.ati&#160;&#160;str&#160;&#160;字符串增强api

    Atitit.ati  str  字符串增强api 1. java StringUtils方法全览 分类: Java2011-11-30 17:22 8194人阅读 评论(2) 收藏 举报 javas ...