HIHO_Disk Storage
2015-11-17 21:55
190 查看
#1100 : Disk Storage
时间限制:10000ms单点时限:1000ms
内存限制:256MB
描述
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:
1. Every disk is placed horizontally. Its axis must coincide with the axis of storage.
2. Every disk is either place on the bottom surface or on another disk.
3. 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.
输入
Input contains only one testcase.The first line contains 4 integers: N(1 <= N <= 100000), M, H, R(1 <= M, R, H <= 100000000).
The second line contains N integers, each number prepresenting the radius of a disk. Each radius is no more than 100000000.
输出
Output the maximum possible number of disks can be put into the storage.样例输入
5 1 10 3 1 3 4 5 10
样例输出
4
解题思路
题目中存在的陷阱为: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.
题目中给出的是:
R(upper)-R(lower)<=M
这时,上层的半径是可以比下层的小的。
按照这种思想,我的解题思路为:
先对整个序列进行从小到大排序,然后从最大值往小值推,当找到第一个半径小于或等于R,记为k时,则可以确保1,2.....k-1都是可以成功放入的。只要找出k+1,k+2,.....n中满足条件的即可。
源码如下:
#include<iostream> #include<math.h> #include<vector> #include<algorithm> using namespace std; int N,M,H,R=0; int main(){ cin>>N>>M>>H>>R; vector<int> data(N,0); for(int i=0;i<N;i++) cin>>data[i]; sort(data.begin(),data.end()); int count=0; int place=-1; for(int i=N-1;i>=0;i--){ if(data[i]<=R){ place=i; count++; break; } } if(place!=-1){ int i=place; for(int j=i+1;j<N;j++){ if(((data[j]-data[j-1])<=M)&&(data[j]<= j+R)) count++; else break; } count=count+place; } cout<<min(count,H)<<endl; return 0; }
相关文章推荐
- vi 中常用命令技巧
- 简述Android 百分比布局支持库(android-percent-support)
- 蓝桥杯 历届试题 矩阵翻硬币
- 【计算机网络】子网掩码什么用?什么是网段?什么叫做在“同一网段”?
- EditText+ListView实现从动态显示数据库数据
- LeetCode题解——Sum Root to Leaf Numbers
- 给大家介绍点技术博客,希望对大家有帮助~
- poj2010
- Firebird 3.0 新功能
- UISegmentedControl
- LeetCode79——Word Search
- Webkit之常用对象API梳理
- hadoop——倒排索引
- Reverse Words in a String
- 【郝斌数据结构自学笔记】12-13_连续存储数组的算法演示
- JMeter处理Cookie与Session
- 【python游戏编程之旅】第二篇--pygame中的IO、数据
- 五笔字根助记词
- 五笔字根助记词
- 使用ViewDragHelper实现slidemenu