Problem Description
My birthday is
coming up and traditionally I'm serving 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.
Input
One line with
a positive integer: the number of test 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.
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 10^(-3).
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
25.1327
3.1416
50.2655
题意:小明过生日朋友来做客,小明用披萨招待他们,有大小不一样的很多披萨,一个朋友分一块,这一块必须是整的,不能一块块的凑起来,并且小明也想吃,每个人必须相同;
解题思路:从最大的饼里求出来最大能分得饼m,然后再1~m之间用二分求最大分饼数,二分的题真是***(脏话自动屏蔽)圆周率需要3.14159265358979323846!!!!
代码(g++)
#include

#include

#include

#define maxn 10010

using namespace std;

double pie[maxn];

double maxn_pie(int n,int f,double pie[])//理想中的能分到的最大披萨

{

    double
sum=0;

    for(int
i=0;i

       
sum+=pie[i];

    return
sum/(f+1);//总共f个朋友加我

}



int main()

{

   
//freopen("in.txt", "r", stdin);

    int
t,n,f;

    double
m_pie=-1,p=0,p1,p2;

   
scanf("%d",&t);

    for(int
i=0;i

    {

       
memset(pie,0,sizeof(pie));

       
m_pie=-1;

       
scanf("%d%d",&n,&f);

       
for(int j=0;j

       
{

           
scanf("%lf",&pie[j]);

           
//注意!!!!pi的精度最少得是我写的这么多,要不后果自负!!!

           
pie[j]=pie[j]*pie[j]*3.14159265358979323846;//每个饼的面积(因为高都是1,所以分面积

//就行了)

           
if(pie[j]>m_pie)

               
m_pie=pie[j];//把最大面积的披萨求出来

       
}

       
//printf("最大的披萨是%.4lf\n",m_pie);

       
p1=0;

       
p2=m_pie;

       
while(p2-p1>1e-6)//开始在最大的披萨中二分来求最大部分披萨了

       
{

           
p=(p1+p2)/2;

           
//printf("p=%.4lf\n",p);

           
int ans=0;

           
for(int i=0;i

               
ans+=(int)(pie[i]/p);//剩下的不要了

           
if(ans>=f+1)

               
p1=p;

           
else if(ans

               
p2=p;

       
}

       
printf("%.4f\n",p1);

    }

}

Pie的更多相关文章

  1. [No0000A2]“原始印欧语”(PIE)听起来是什么样子?

    "Faux Amis"节目中经常提到"原始印欧语"(PIE)——"Proto-Indo-European". 我们说过,英语,法语中的&qu ...

  2. poj3311 Hie with the Pie (状态压缩dp,旅行商)

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3160   Accepted: 1613 ...

  3. pygame 练习之 PIE game (以及简单图形训练)

    简单的大饼游戏,掌握pygame中直线以及圆弧的画法,以及对输入的响应. import math import pygame, sys from pygame.locals import * pyga ...

  4. Pizza Pie Charts – 基于 Snap SVG 框架的响应式饼图

    Pizza Pie Charts 是一个基于 Adobe 的 Snap SVG 框架的响应式饼图插件.它着重于集成 HTML 标记和 CSS,而不是 JavaScript 对象,当然Pizza Pie ...

  5. 【poj3122】 Pie

    http://poj.org/problem?id=3122 (题目链接) 题意 给出N个pie的半径和F个friend,每个friend得到的pie必须一样,求每个人能得到的pie的最大大小. so ...

  6. tcpdump for android L 5.x with pie support

    由于使用了NDK编译的可执行文件在应用中调用,在4.4及之前的版本上一直没出问题. 最近由于要测试在Android L上的运行情况发现,当运行该可执行文件时,报如下错误: error: only po ...

  7. 分馅饼 Pie

    Pie 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C 题目: Problem Description ...

  8. Pie(二分POJ3122)

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12985   Accepted: 4490   Special Ju ...

  9. poj3122 pie

    方法:二分. 题目意思:要过生日了,我请大家吃pie,然后人数一共是f+1(我自己).每个人的pie不能是拼接的,而且每个人的面积是一样的,这样就用二分枚举. 范围是0-最大的那块pie. 然后用每一 ...

  10. PIC和PIE

    PIC指的是位置无关代码,用于生成位置无关的共享库,所谓位置无关,指的是共享库的代码断是只读的,存放在代码段,多个进程可同时公用这份代码段而不需要拷贝副本.库中的变量(全局变量和静态变量)通过GOT表 ...

随机推荐

  1. android自定义动画

    前一篇说了实现过程,这次来写一个自己简单实现的3d动画 先来属性声明配置,方便使用xml 文件来定制动画 <!-- 有些类型其实是没必要的,只是实例代码,为了更具有代表性 --> < ...

  2. js两个叹号的使用

    1.浏览器判断空和未定义以及零时返回的值如下: alert(undefined)  //undefined alert(null)  //null alert(0)  //0 2.有时为了便于下一步判 ...

  3. mongoDB学习手记2--建库、删库、插入、更新

    上一篇  讲了在windows系统下的安装和启动,本文主要讲怎么建库.删库.插入.更新 在讲之前我们说一下mongoDB的一些基本概念,我们对比关系型数据库能更直观的理解 SQL术语/概念 Mongo ...

  4. 安装Appium

    1.Appium官方网站:http://appium.io/ 拉到页面底端显示下面一段描述: > brew install node # get node.js > npm install ...

  5. oracle数据中记录被另一个用户锁住

    原因:PL/SQL里面执行语句执行了很久都没有结果,于是中断执行,于是就直接在上面改字段,在点打钩(记入改变)的时候提示,记录被另一个用户锁住. 解决方法: 第一步:(只是用于查看哪些表被锁住,真正有 ...

  6. Hive基础(2)---(启动HiveServer2)Hive严格模式

    启动方式 1, hive  命令行模式,直接输入/hive/bin/hive的执行程序,或者输入 hive –service cli 用于linux平台命令行查询,查询语句基本跟mysql查询语句类似 ...

  7. bzoj4198 荷马史诗 哈夫曼编码

    逐影子的人,自己就是影子. --荷马 Allison 最近迷上了文学.她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的<荷马史诗>.但是由<奥德赛>和&l ...

  8. Window2008 R2(64位)使用codesmith连接Sqlite

    ①打开C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config目录,找到machine.config文件新增 <add name=" ...

  9. 关于Android SDK Manager无法获取更新列表的正确设置

    1.以"管理员身份运行"SDK Manager. 2.Android SDK Manager"=>"Tools"=>"Optio ...

  10. NSOperation与GCD的如何选择?

    iOS开发的多线程实现方式,大概包括C的原始方式.NSThread方式.GCD.NSOperation的方式. 其中用的最多的应该是GCD和NSOperation的方式,很多第三方库都是使用了这两种方 ...