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个时刻, ...
随机推荐
- PyTorch学习笔记之计算图
1. **args, **kwargs的区别 def build_vocab(self, *args, **kwargs): counter = Counter() sources = [] for ...
- Spring配置项之<aop:aspectj-autoproxy />
通过配置织入@Aspectj切面 虽然可以通过编程的方式织入切面,但是一般情况下,我们还是使用spring的配置自动完成创建代理织入切面的工作. 通过aop命名空间的<aop:aspectj-a ...
- ZooKeeper 授权验证
ZooKeeper 授权验证 学习了:https://blog.csdn.net/liuyuehu/article/details/52121755 zookeeper可以进行认证授权:
- 转:android studio入门合集
http://blog.csdn.net/column/details/zsl-androidstudio.html
- Raid分类说明 (from mongodb权威指南)
RAID(Redundant Array of Independent Disk,独立磁盘冗余阵列,旧称Redundant Array of InexpensiveDisk,廉价磁盘冗余阵列) 是一种 ...
- Android Camera探究之路——起步
Android Camera探究之路--起步 Camera在手机中有着举足轻重的地位,无论是二维码还是照片.识别.都离不开摄像头,本文将对Android中的Camera进行全面解析. 权限镇楼: &l ...
- http 错误代码一览表
http协议一些常见的状态码为: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第一部分 ...
- C中參数个数可变的函数
一.什么是可变參数 我们在C语言编程中有时会遇到一些參数个数可变的函数,比如printf()函数,其函数原型为: int printf( const char* format, ...); 它除了有一 ...
- nice命令兼容性分析实例
背景 产品实验室出现一例日志转储问题,经定位发现当前版本号没有提供nice命令,而cron拉起定时任务时,却调用了nice命令,对定时任务做优先级调整. 毫无疑问兴许版本号须要提供nice命令,可是是 ...
- SVProgressHUD 用法一
SVProgressHUD 用法一 SVProgressHUD 是一个第三方的控件,是一个弹出提示层,用来提示 网络加载 或 提示对错,看下面图,你就明白了: 那么,SVProgressHU ...