Created
January 5, 2015 14:50
-
-
Save HaiyangXu/51257ec691a757ce5f51 to your computer and use it in GitHub Desktop.
题目2 : Disk Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <queue> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
#include <cmath> | |
#include <ctime> | |
#include <cstdio> | |
#include <cstring> | |
#include <cstdlib> | |
using namespace std; | |
typedef vector<int>::iterator IT; | |
vector<int> disks; | |
vector<bool> flag; | |
int M; | |
int maxdisk(int H,int R,int x,int counts){ | |
if(H==0||counts>=disks.size())return 0; | |
int maxval=0; | |
IT it= upper_bound(disks.begin(), disks.end(), min(R,x)); | |
for(IT i=disks.begin();i!=it;i++){ | |
int loc=int(i-disks.begin()); | |
if (flag[loc]) { | |
flag[loc]=false; | |
maxval=max(maxval,1+maxdisk(H-1, R+1, *i+M,counts+1)); | |
flag[loc]=true; | |
} | |
} | |
return maxval; | |
} | |
int main() | |
{ | |
#ifndef ONLINE_JUDGE | |
freopen("input.txt", "r", stdin); | |
#endif | |
int N,R,H; | |
cin>>N>>M>>H>>R; | |
int disk; | |
while(N--){ | |
cin>>disk; | |
disks.push_back(disk); | |
} | |
flag.resize(disks.size()); | |
fill(flag.begin(),flag.end(),true); | |
cout<<maxdisk(H,R,R,0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://hihocoder.com/contest/mstest2015jan1/problem/2
题目2 : Disk Storage
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
1.png
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:
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