B - Pie
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
分蛋糕,包括自己,每个人的面积要最大,每个人只能有一种蛋糕;
用二分的方法就可以了
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mem(a,b) memset(a,b,sizeof(a))
const double pi=acos(-1.0);
typedef long long ll;
typedef long double ld;
const ll MOD=1e9+7;
using namespace std;
int n,m;
int a[10005];
bool judge(double mid)
{
int ans=0;
for(int i=0;i<n;i++)
{
ans=ans+(int)(a[i]*a[i]*pi/mid);
}
if(ans>=m)
return true;
else
return false;
}
int main()
{
int re;
cin>>re;
while(re--)
{
double sum=0;
mem(a,0);
sf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
sf("%d",&a[i]);
sum+=a[i]*a[i]*pi;
}
m++;
double left=0,right=sum/m;
double mid=(left+right)/2;
while(right-left>0.0001)
{
if(judge(mid))
left=mid;
else
right=mid;
mid=(left+right)/2;
}
pf("%.4lf\n",mid);
}
return 0;
}
B - Pie的更多相关文章
- [No0000A2]“原始印欧语”(PIE)听起来是什么样子?
"Faux Amis"节目中经常提到"原始印欧语"(PIE)——"Proto-Indo-European". 我们说过,英语,法语中的&qu ...
- poj3311 Hie with the Pie (状态压缩dp,旅行商)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3160 Accepted: 1613 ...
- pygame 练习之 PIE game (以及简单图形训练)
简单的大饼游戏,掌握pygame中直线以及圆弧的画法,以及对输入的响应. import math import pygame, sys from pygame.locals import * pyga ...
- Pizza Pie Charts – 基于 Snap SVG 框架的响应式饼图
Pizza Pie Charts 是一个基于 Adobe 的 Snap SVG 框架的响应式饼图插件.它着重于集成 HTML 标记和 CSS,而不是 JavaScript 对象,当然Pizza Pie ...
- 【poj3122】 Pie
http://poj.org/problem?id=3122 (题目链接) 题意 给出N个pie的半径和F个friend,每个friend得到的pie必须一样,求每个人能得到的pie的最大大小. so ...
- tcpdump for android L 5.x with pie support
由于使用了NDK编译的可执行文件在应用中调用,在4.4及之前的版本上一直没出问题. 最近由于要测试在Android L上的运行情况发现,当运行该可执行文件时,报如下错误: error: only po ...
- 分馅饼 Pie
Pie 链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/C 题目: Problem Description ...
- Pie(二分POJ3122)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12985 Accepted: 4490 Special Ju ...
- poj3122 pie
方法:二分. 题目意思:要过生日了,我请大家吃pie,然后人数一共是f+1(我自己).每个人的pie不能是拼接的,而且每个人的面积是一样的,这样就用二分枚举. 范围是0-最大的那块pie. 然后用每一 ...
- PIC和PIE
PIC指的是位置无关代码,用于生成位置无关的共享库,所谓位置无关,指的是共享库的代码断是只读的,存放在代码段,多个进程可同时公用这份代码段而不需要拷贝副本.库中的变量(全局变量和静态变量)通过GOT表 ...
随机推荐
- 用oc写爬虫之HTMLParser
最近刚好有一些小需求,就尝试用OC来写一些简单的爬虫抓取网页上的数据: 发现了一个非常好用的HTMLParser工具 ; 语法是OC的,通过分析网页结构:可以很轻松的抓取需要的数据: 但是提前需要了解 ...
- POCO Log库
http://pocoproject.org/index.html 有个想法,把这个所谓的跨平台log库阉割成只支持win的,然后使代码尽量简化,高效,以后有时间就开始研究,哈哈.
- mark 阿里支付
开源软件企业版特惠高校版博客 我的码云 ·· 8月18日(周六)成都源创会火热报名中,四位一线行业大牛与你面对面,探讨区块链技术热潮下的冷思考. 开源项目 > WEB应用开发 > Web开 ...
- sonarqube 自动代码审查
1.docker 拉取sonarqube docker pull sonarqube 2.启动docker docker run -d --name sonarqube -p 9000:9000 so ...
- js 学习
{% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- 浅析Mysql的my.ini文件
转载:http://hunanpengdake.iteye.com/admin/blogs/1647725 今天闲的蛋疼,没事想了解mysql,大家都知道在配置Mysql的过程中,my.ini非常重要 ...
- flutter 环境安装以及配置
首先需要下载flutter源码,以下是github地址: https://github.com/flutter/flutter 然后需要安装git环境吧,下图红框可以自行下载安装 接下来需要安装flu ...
- 《ZooKeeper分布式专题与Dubbo微服务入门》
最近在慕课网新上的课程,有兴趣的朋友可以关注一波 http://coding.imooc.com/class/201.html
- Features Download Pricing Mind Maps Blog XMind的快捷键
XMind提供很多快捷键.使用XMind时,在操作的过程中结合快捷键,双手同时操作,将给你带来很大的便利.例如下面一些常用的快捷键: 编辑主题:F2 添加标签:F3 创建一个新的空白工作簿:Ctrl+ ...
- JAVA 线程池架构浅析
经历了Java内存模型.JUC基础之AQS.CAS.Lock.并发工具类.并发容器.阻塞队列.atomic类后,我们开始JUC的最后一部分:线程池.在这个部分你将了解到下面几个部分: 线程池的基础架构 ...