hdu 1969 Pie(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969
Pie
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4513 Accepted Submission(s):
1819
pie. Not just one pie, no, I have a number N of them, of various tastes and of
various sizes. F of my friends are coming to my party and each of them gets a
piece of pie. This should be one piece of one pie, not several small pieces
since that looks messy. This piece can be one whole pie though.
My
friends are very annoying and if one of them gets a bigger piece than the
others, they start complaining. Therefore all of them should get equally sized
(but not necessarily equally shaped) pieces, even if this leads to some pie
getting spoiled (which is better than spoiling the party). Of course, I want a
piece of pie for myself too, and that piece should also be of the same size.
What is the largest possible piece size all of us can get? All the pies
are cylindrical in shape and they all have the same height 1, but the radii of
the pies can be different.
cases. Then for each test case:
---One line with two integers N and F with 1
<= N, F <= 10 000: the number of pies and the number of friends.
---One
line with N integers ri with 1 <= ri <= 10 000: the radii of the
pies.
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 10^(-3).
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; #define PI acos(-1.0) int main ()
{
int t;
while (~scanf("%d",&t))
{
while (t--)
{
int n,f,r;
double V[],v=,vmax;
scanf("%d%d",&n,&f);
f=f+;
for (int i=; i<n; i++)
{
scanf("%d",&r);
V[i]=r*r*PI;
v+=V[i];
//cout<<v<<endl;
}
vmax=v/f;
double left,right,mid;
left=;
right=vmax;
int ans;
while ((right-left)>1e-)
{
int flag=,k=;
ans=;
mid=(left+right)/;
for (int i=;i<n;i++)
{
// ans+=(int)(V[i]/mid);
//if (ans>=f)
//flag=1;
double vv=V[i];
while(vv>=mid)
{
vv-=mid;
k++;
//cout<<vv<<" "<<k<<endl;
if(k==f)
{
flag=;
break;
}
}
if(flag==) break;
}
if(flag==)
left=mid;
else
right=mid;
}
printf("%.4lf\n",mid);
}
}
return ;
}
另外一种
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; #define PI acos(-1.0) int main ()
{
int t;
while (~scanf("%d",&t))
{
while (t--)
{
int n,f,r;
double V[],v=,vmax;
scanf("%d%d",&n,&f);
f=f+;
for (int i=; i<n; i++)
{
scanf("%d",&r);
V[i]=r*r*PI;
v+=V[i];
//cout<<v<<endl;
}
vmax=v/f;
double left,right,mid;
left=;
right=vmax;
int ans;
while ((right-left)>1e-)
{
int flag=,k=;
ans=;
mid=(left+right)/;
for (int i=;i<n;i++)
{
ans+=(int)(V[i]/mid);
if (ans>=f)
flag=;
if(flag==) break;
}
if(flag==)
left=mid;
else
right=mid;
}
printf("%.4lf\n",mid);
}
}
return ;
}
hdu 1969 Pie(二分查找)的更多相关文章
- HDU 1969 Pie(二分查找)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- (step4.1.2)hdu 1969(Pie——二分查找)
题目大意:n块馅饼分给m+1个人,每个人的馅饼必须是整块的,不能拼接,求最大的. 解题思路: 1)用总饼的体积除以总人数,得到每个人最大可以得到的V.但是每个人手中不能有两片或多片拼成的一块饼. 代码 ...
- HDU 1969 Pie(二分,注意精度)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1969 Pie [二分]
1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...
- 题解报告:hdu 1969 Pie(二分)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- 【hoj】2651 pie 二分查找
二分查找是一个非常主要的算法,针对的是有序的数列,通过中间值的大小来推断接下来查找的是左半段还是右半段,直到中间值的大小等于要找到的数时或者中间值满足一定的条件就返回,所以当有些问题要求在一定范围内找 ...
- Can you find it? HDU - 2141 (二分查找)
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...
- HDU 1969 Pie【二分】
[分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...
- hdu 1969 pie 卡精度的二分
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
随机推荐
- ServiceMessage
<?php class ServiceMessage { private $errorCode = array( '1000' => "系统错误", '1001' =& ...
- tomcat 相关
servlet.xml 文件: 1 . 修改端口号,找到如下标签,port 属性就是端口号,修改之后重启服务器即可, <Connector connectionTimeout="200 ...
- wpf 验证方法
效果图,当放鼠标到文本框上会显示出错的提示.
- 限制玻尔兹曼机(Restricted Boltzmann Machine)RBM
假设有一个二部图,每一层的节点之间没有连接,一层是可视层,即输入数据是(v),一层是隐藏层(h),如果假设所有的节点都是随机二值变量节点(只能取0或者1值)同时假设全概率分布满足Boltzmann 分 ...
- POJ2724:Purifying Machine——题解
http://poj.org/problem?id=2724 描述迈克是奶酪工厂的老板.他有2^N个奶酪,每个奶酪都有一个00 ... 0到11 ... 1的二进制数.为了防止他的奶酪免受病毒侵袭,他 ...
- windows内存映射文件
http://shushanyegui.duapp.com/?p=731 在描述内存映射文件之前 我们先来写一个系统通过I/O来读写磁盘文件的小程序 #include "stdafx.h&q ...
- HTML5 canvas 创意:飞翔的凤凰
当我看到这件作品的时候,我表示非常喜欢.这个作品的产生不仅仅需要编程和算法,作者肯定是个充满了艺术细胞的人.倘若有什么canvas艺术作品比赛的话,我想它就是获奖的那个. 先观赏下演示吧.注意,要看到 ...
- Multi-target tracking with Single Moving Camera
引自:http://www.eecs.umich.edu/vision/mttproject.html Wongun Choi, Caroline Pantofaru, Silvio Savarese ...
- snmp代码篇
相关链接:Snmp学习笔记使用snmp4j实现Snmp功能(一)使用snmp4j实现Snmp功能(二)使用snmp4j实现Snmp功能(三) SNMP是英文“Simple Network Manage ...
- ACE主动对象模式(1)
转载于:http://www.cnblogs.com/TianFang/archive/2006/12/11/589168.html 主动对象模式用于降低方法执行和方法调用之间的耦合.该模式描述了另外 ...