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. java实现excel和数据的交互

    1. 环境要求 本文环境为: 数据库为oracle,jdk为jdk7,依赖jar包为ojdbc6-11.2.0.4.0.jar+poi-3.14.jar 2.POI 使用 1. 建立工作空间 2. 获 ...

  2. jQuery自定义插件--banner图滚动

    前言 jQuery是一个功能强大的库,提供了开发JavaScript项目所需的所有核心函数.很多时候我们使用jQuery的原因就是因为其使用插件的功能,然而,有时候我们还是需要使用自定义代码来扩展这些 ...

  3. 我的第一个python web开发框架(1)——前言

    由于之前经验不是很丰富,写的C#系统太过复杂,所以一直想重写,但学的越多越觉得自己懂的越少,越觉的底气不足.所以一直不敢动手,在内心深处对自己讲,要静下心来认真学习,继续沉淀沉淀.这两年多以来找各种机 ...

  4. UI自动化测试(四)AutoIT工具使用和robot对象模拟键盘按键操作

    AutoIT简介 AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/ ...

  5. Dice (II) (DP)唉,当时没做出来

    Dice (II) Time Limit: 3000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu [Submit]   [ ...

  6. php中常用的字符串截取函数mb_substr实例解释

    string mb_substr ( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_ ...

  7. Java总结篇:Java多线程

    Java总结篇系列:Java多线程 多线程作为Java中很重要的一个知识点,在此还是有必要总结一下的. 一.线程的生命周期及五种基本状态 关于Java中线程的生命周期,首先看一下下面这张较为经典的图: ...

  8. docker命令不需要敲sudo的方法

    由于docker daemon需要绑定到主机的Unix socket而不是普通的TCP端口,而Unix socket的属主为root用户,所以其他用户只有在命令前添加sudo选项才能执行相关操作. 如 ...

  9. Java历程-初学篇 Day06 循环结构

    前记:永远不要写死循环 一,while循环 先判断,再执行 while(条件){ //代码块; 迭代; } 示例: 二,do while语句 先执行一次,再判断 do{ //代码块; 迭代; }whi ...

  10. SqlServer和Oracle中一些常用的sql语句9 SQL优化

    --SQL查询优化 尽量避免使用or,not,distinct运算符,简化连接条件 /*Or运算符*/ use db_business go select * from 仓库 where 城市='北京 ...