Piece of Cake
2016-04-26 13:33
375 查看
Piece of Cake
Time Limit:1000MS Memory Limit:65536K
Total Submit:69 Accepted:13
Description
The annual neonatal trials will start next week, at the same time, all old guys of the ACM teams want to reward all M students who work hard in the match.
So, we buy N cakes which are of different radius. Consider the height of each cake is 1.
However, Master Ye consider that every student should assign to the equal size of cake, which means every cake assigned to students should be the same volume. Also, he mentions, one student should assign only one piece of cake.
Master Ye want you to calculate the maximum volume that every student can get. Can you help him figure out this problem?
Input
The first line contain the number of test cases,no more than 20.
The second line contain two integers,1 ≤ N, M ≤ 65536 which means the number of cakes and students
Then following one line contain N integers represent each cake’s radius,and 1 ≤ r ≤ 65536.
Output
For each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be
given as a floating point number with an absolute error of at most 1e−4.
Sample Input
Sample Output
题意:给定n个蛋糕的半径以及人数k,现在要求k个人每人只能获得一块蛋糕并且体积相同,问他们最多能得到体积为多少的蛋糕。
题解:因为每个人只能获得一块蛋糕,所以假设他们能得到的体积为V,第i个蛋糕的体积为cake[i],那么第i个蛋糕可能分成(int)(cake[i]/V)个蛋糕。
我们可以二分体积,然后暴力一遍这个体积能否凑满k块,如果可以,就让V再大点,反之,则让V小一点。
代码:
//************************************************************************//
//*Author : Handsome How *//
//************************************************************************//
//#pragma comment(linker, "/STA CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double pi=acos(-1);
//----------------------------------------------------------
ll rr[66666];
int main()
{
int T,kase=0;
ll all;
scanf("%d",&T);
while(T--){
all = 0;
int cake,pep,t;
scanf("%d %d",&cake,&pep);
for(int i=1;i<=cake;i++){
scanf("%d",&t);
rr[i]=t*t*1ll;
all+=rr[i];
}
double l=0,r = (double)all;
while(r-l>(1e-5)){
double mid=(l+r)/2.0;
int tot = 0,now = cake;
for(int i = 1;i<=cake;i++)
tot+=(int)(rr[i]/mid);
if(tot>=pep)l=mid;
else r=mid;
}
printf("Case#%d: ",++kase);
printf("%.3lf\n",r*pi);
}
return 0;
}
Time Limit:1000MS Memory Limit:65536K
Total Submit:69 Accepted:13
Description
The annual neonatal trials will start next week, at the same time, all old guys of the ACM teams want to reward all M students who work hard in the match.
So, we buy N cakes which are of different radius. Consider the height of each cake is 1.
However, Master Ye consider that every student should assign to the equal size of cake, which means every cake assigned to students should be the same volume. Also, he mentions, one student should assign only one piece of cake.
Master Ye want you to calculate the maximum volume that every student can get. Can you help him figure out this problem?
Input
The first line contain the number of test cases,no more than 20.
The second line contain two integers,1 ≤ N, M ≤ 65536 which means the number of cakes and students
Then following one line contain N integers represent each cake’s radius,and 1 ≤ r ≤ 65536.
Output
For each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be
given as a floating point number with an absolute error of at most 1e−4.
Sample Input
3 3 3 4 3 3 1 24 5 10 5 1 4 2 3 4 5 6 5 4 2
Sample Output
Case#1: 28.274 Case#2: 3.272 Case#3: 50.265
题意:给定n个蛋糕的半径以及人数k,现在要求k个人每人只能获得一块蛋糕并且体积相同,问他们最多能得到体积为多少的蛋糕。
题解:因为每个人只能获得一块蛋糕,所以假设他们能得到的体积为V,第i个蛋糕的体积为cake[i],那么第i个蛋糕可能分成(int)(cake[i]/V)个蛋糕。
我们可以二分体积,然后暴力一遍这个体积能否凑满k块,如果可以,就让V再大点,反之,则让V小一点。
代码:
//************************************************************************//
//*Author : Handsome How *//
//************************************************************************//
//#pragma comment(linker, "/STA CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double pi=acos(-1);
//----------------------------------------------------------
ll rr[66666];
int main()
{
int T,kase=0;
ll all;
scanf("%d",&T);
while(T--){
all = 0;
int cake,pep,t;
scanf("%d %d",&cake,&pep);
for(int i=1;i<=cake;i++){
scanf("%d",&t);
rr[i]=t*t*1ll;
all+=rr[i];
}
double l=0,r = (double)all;
while(r-l>(1e-5)){
double mid=(l+r)/2.0;
int tot = 0,now = cake;
for(int i = 1;i<=cake;i++)
tot+=(int)(rr[i]/mid);
if(tot>=pep)l=mid;
else r=mid;
}
printf("Case#%d: ",++kase);
printf("%.3lf\n",r*pi);
}
return 0;
}
相关文章推荐
- 内容提供者ContentProvider的基本使用
- Lighttpd中CGI执行流程
- JavaScript日期集合(今日,昨日,本周一,周末 ,月初,月末)
- iOS 开发系列之在应用中添加TouchID 验证身份
- 手机APP界面-UI设计教程
- IIS服务器不能下载.apk文件的解决方略
- 正则表达式
- JAVA流
- 【leetcode】128. Longest Consecutive Sequence
- selector.xml无效的解决办法
- iOS集成友盟分享时的一些问题
- 45个JavaScript小技巧
- servlet get post with html
- 去耦电容和旁路电容详解
- Javascript 严格模式详解
- Node.js应用场景及发展趋势
- popupwindow显示的位置 布局的右上角,标题栏下
- (ql)30W单片精密开关电源 电路图加分析
- 团队会议第八天
- Ctrl-A全选这点事(C#,WinForm)