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表 ...
随机推荐
- boost 线程安全队列
threadnullmethodsprocessingobjectsignal // QueueImplementation.cpp : Defines the entry point for the ...
- 版本控制-GitHub
前面几篇文章,我们介绍了Git的基本用法及Git服务器的搭建,本篇文章来学习一下如何使用GitHub.GitHub是开源的代码库以及版本控制库,是目前使用网络上使用最为广泛的服务,GitHub可以托管 ...
- C# Chart使用总结 1 ---------关于图表数据的来源
关于图表数据的来源: 1.通过XValueMember YValueMembers 设置 OleDbConnection conn = new OleDbConnection(connStr); Ol ...
- VBScript.RegExp 正则表达式excel vba 学习经验
1) 手动引用(前期绑定) 点击VBE编辑器菜单:工具 - 引用,选取: Microsoft VBScript Regular Expressions 5.5 Dim regex As New ...
- fiddler模拟发送get/post请求(也可做简单接口测试)
1.模拟发送请求 (1)fiddler设置post接口信息及参数,点击execute发送请求 (2)fiddler设置get接口信息及参数,点击execute发送请求 2.发送请 ...
- Git教程学习(二)
教程来自: Git教程(廖雪峰的官方网站) 主要命令: $ git log #查看已提交内容 $ git log --pretty=oneline #查看已提交内容(紧凑版) $ git reset ...
- 【读书笔记】Data_Mining_with_R---Chapter_2_Predicting Algae Blooms
本书概要 <Data Mining with R>这本书通过实例,并结合R讲解数据挖掘技术.本书的核心理念就是"Learning it by doing".本书分5章, ...
- 【Python】将python3.6软件的py文件打包成exe程序
下载pyinstaller pyinstaller 改变图标 pyinstaller -F --icon=my.ico xxx.py 采用命令行操作的办法 在cmd命令行中,输入代码: 首先,前往Py ...
- Android Launcher分析和修改2——Icon修改、界面布局调整、壁纸设置
上一篇文章说了如何修改Android自带Launcher2的默认界面设置(http://www.cnblogs.com/mythou/p/3153880.html). 今天主要是说说Launcher里 ...
- Godot游戏引擎 3.0 Beta2 于12月21日发布
Beta版继续在修复bug.其官方表示原计划在今年的圣诞节发布3.0 Stable版的,但看来只能继续跳票. 由于开发力量比较单薄,新版本的开发进展算是比较慢的,但3.0这个版本值得期待. Godot ...