http://poj.org/problem?id=3122

题意

主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一个派上切下来的。

分析

二分答案,每次统计当前体积下能分配的人数。

#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lc idx<<1
#define rc idx<<1|1
#define rson mid+1,r,rc
#define lson l,mid,lc
using namespace std;
typedef long long ll;
template <class T>
void test(T a) {
cout<<a<<endl;
}
template <class T,class T2>
void test(T a,T2 b) {
cout<<a<<" "<<b<<endl;
}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c) {
cout<<a<<" "<<b<<" "<<c<<endl;
}
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = 1e9+;
int T;
void testcase() {
printf("Case %d: ",++T);
}
const int MAXN = 1e5+;
const int MAXM = ;
const double PI = acos(-1.0);
const double eps = 1e-;
double pie[MAXN];
int n,m;
int main() {
#ifdef LOCAL
freopen("data.in","r",stdin);
#endif // LOCAL
int T;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
double maxx = ;
for(int i=; i<n; i++) {
scanf("%lf",&pie[i]);
pie[i] *= pie[i];
if(maxx<pie[i]) {
maxx = pie[i];
}
}
m = m + ;
double l = ;
double r = maxx;
double mid;
while(r-l>eps) {
mid = (r+l)/;
int sum = ;
for(int i=; i<n; i++) {
if(pie[i]-mid>eps) {
sum += (int)pie[i]/mid;
}
}
if(sum>=m) l = mid;
else r = mid;
}
printf("%.4f\n",mid*PI);
}
return ;
}

POJ - 3122 Pie(二分)的更多相关文章

  1. POJ 3122 Pie 二分枚举

    题目:http://poj.org/problem?id=3122 这个题就好多了,没有恶心的精度问题,所以1A了.. #include <stdio.h> #include <ma ...

  2. POJ 3122 Pie 二分答案

    题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...

  3. poj 3122 (二分查找)

    链接:http://poj.org/problem?id=3122 Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

  4. 【POJ】3122 Pie [二分查找]

    题目地址:http://poj.org/problem?id=3122 二分每块饼的体积.为了保证精度,可以先二分半径的平方r*r,最后再乘以PI.要注意一点,要分的人数要包括自己,及f+1. #in ...

  5. POJ 3122 Pie (贪心+二分)

    My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...

  6. POJ 3122 Pie【二分答案】

    <题目链接> 题目大意: 将n个半径不一但是高度为1的蛋糕分给 F+1个人,每个人分得蛋糕的体积应当相同,并且需要注意的是,每个人分得的整块蛋糕都只能从一个蛋糕上切下来,而不是从几个蛋糕上 ...

  7. POJ 3122 Pie(二分+贪心)

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22684   Accepted: 7121   Special Ju ...

  8. POJ 3122 Pie

    题目大意: 给出n个pie的直径,有f+1个人,如果给每人分的大小相同(形状可以不同),每个人可以分多少.要求是分出来的每一份必须出自同一个pie,也就是说当pie大小为3,2,1,只能分出两个大小为 ...

  9. poj 3122(二分查找)

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13564   Accepted: 4650   Special Ju ...

随机推荐

  1. ESXi安装时遇到不识别的硬件的处理

    1. 部门新购置了一台inspur 四路 NF8480M4的服务器. 上架之后发现ESXi的标准安装盘无法安装. 找不到磁盘安装介质. 2. 处理办法, 找浪潮专家服务,报上序列号,要上相关的一些软件 ...

  2. 关于Laravel中使用response()方法调用json()返回数据unicode编码转换的问题解决

    在网上找了好久没有找到,之后一步一步测试,发现了Laravel还是很强大的,解决方案如下: public function response(){ // 返回json数据 $data = [ 'err ...

  3. ES next & Async Await

    ES next & Async Await https://jestjs.io/docs/en/asynchronous#async-await ES7 new async () => ...

  4. C++ 日期时间使用

    #include <time.h> #include <stdio.h> #include <iostream> #include <string> # ...

  5. HDU-5373-水题-卡常数时间

    姿势就是力量啊! 第一次意识到long long 比 int要慢很多.当时想到了各种优化仍然TLE,最后也没A出来,就是用了long long #include <cstdio> #inc ...

  6. GO系列教程

    1.介绍与安装 2.Hello World 3.变量 4. 类型 5.常量 6.函数(Function) 7.包 8.if-else 语句 9.循环 10.switch语句 11.数组和切片 12.可 ...

  7. zxing生成二维码设置边框颜色

    真是研究了很久很久,满满的泪啊 zxing生成二维码,默认是可以增加空白边框的,但是并没有可以设置边框颜色的属性. 其中增加空白边框的属性的一句话是: Map hints = new HashMap( ...

  8. android 组件使用()

    程序入口点 类似于win32程序里的WinMain函数,Android自然也有它的程序入口点.它通过在AndroidManifest.xml文件中配置来指明,可以看到名为NotesList的activ ...

  9. Java:判断当前操作系统界面采用的主题是windows经典样式还是xp样式

    想起两三年前,发现写Java界面的时候,如果将当前界面的layout设为null,由于windows的不同主题界面下,标题栏的高度不一致,导致当前界面表现也不一致. 当时就想找到一个办法先判断当前用户 ...

  10. Web应用:当文件超过100KB,无法上传,有种原因你想象不到

    今天下午2点多,突然发现凡是文件超过100KB的,在上传的时候都会卡住,但低于100KB的文件可以上传成功. 服务器端使用的是asp无组件上传,为什么突然出现这种问题呢? 我们知道,IIS默认上传限制 ...