Disk Storage
2015-11-15 21:20
381 查看
描述
Little Hi and Little Ho have a disk storage. The storage’s shape is a truncated cone of height H. R+H is radius of top circle and R is radius of base circle.
Little Ho buys N disks today. Every disk is a cylinder of height 1. Little Ho wants to put these disk into the storage under below constraints:
Every disk is placed horizontally. Its axis must coincide with the axis of storage.
Every disk is either place on the bottom surface or on another disk.
Between two neighboring disks in the storage, the upper one’s radius minus the lower one’s radius must be less than or equal to M.
Little Ho wants to know how many disks he can put in the storage at most.
题目分析
由于容器是个倒梯形的,因此摆放时小的放下面,大的放上面。因此我们考虑将所有的disk按升序排序。
排序后我们发现,disk会因为第三个条件分成多段,不同段是不能放在一起的,比如在M= 1时
1, 2, 3, 5, 6, 7, 9, 10,
就被分成了三段:1, 2, 3# 5, 6, 7# 9, 10 各段内部满足条件3,因此可以从各段中选择一段放置在容器内。
对于小于R的盘,可以按照倒序的方式扣在已经放好的盘上,因此还要加上小于R且没有被使用的盘。
代码:
下面代码的思路是,先在R所在段出能够放置的disk数,然后加上小于R的disk数。
#include <cstdio> #include <algorithm> using namespace std; enum {maxn = 100000+5}; int a[maxn]; int main() { int n, m, h, r; scanf("%d %d %d %d", &n, &m, &h, &r); for (int i=0; i<n; i++) scanf("%d", a+i); sort(a, a+n); if (a[0] > r) { printf("0\n"); return 0; } int br1 = 0; int i; for(i=1; i<n && a[i]<=r; i++) { if (a[i]- a[i-1] > m) br1 = i; } int push = i - br1 -1; for (int j= 1; i<n ; i++, j++) { if (a[i]- a[i-1] > m) break; if (a[i] > r+j+push) break; } printf("%d\n", min(i, h)); return 0; }
相关文章推荐
- #1094 : Lost in the City
- hiho 挑战赛16 A.王胖浩与三角形
- hiho 挑战赛16 B 王胖浩与环
- hiho 1228 Mission Impossible 6
- 【hiho一下】第一周 最长回文子串
- 【hiho一下】第二周 Trie树
- 【hiho一下】第三周 KMP算法
- 【hiho一下】第五周 数字三角形
- hihocoder 状态压缩二
- #1051 : 补提交卡
- [hihoCoder]#1325 : 平衡树·Treap(平衡树)
- hiho#1039 : 字符消除,题解
- hihoCoder--1039:字符消除
- 智力竞赛(hiho145周)
- 后缀自动机学习笔记1(hiho127周)
- Eular质数筛法
- [Hiho]1015-KMP算法
- hihoCoder:1039字符串消除(当你找不到自己错在哪里了,可以来我这里看一看)
- hiho #1094 : Lost in the City
- hiho #1082 : 然而沼跃鱼早就看穿了一切