POJ - 3122 Pie(二分)
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(二分)的更多相关文章
- POJ 3122 Pie 二分枚举
题目:http://poj.org/problem?id=3122 这个题就好多了,没有恶心的精度问题,所以1A了.. #include <stdio.h> #include <ma ...
- POJ 3122 Pie 二分答案
题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...
- poj 3122 (二分查找)
链接:http://poj.org/problem?id=3122 Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
- 【POJ】3122 Pie [二分查找]
题目地址:http://poj.org/problem?id=3122 二分每块饼的体积.为了保证精度,可以先二分半径的平方r*r,最后再乘以PI.要注意一点,要分的人数要包括自己,及f+1. #in ...
- POJ 3122 Pie (贪心+二分)
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...
- POJ 3122 Pie【二分答案】
<题目链接> 题目大意: 将n个半径不一但是高度为1的蛋糕分给 F+1个人,每个人分得蛋糕的体积应当相同,并且需要注意的是,每个人分得的整块蛋糕都只能从一个蛋糕上切下来,而不是从几个蛋糕上 ...
- POJ 3122 Pie(二分+贪心)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22684 Accepted: 7121 Special Ju ...
- POJ 3122 Pie
题目大意: 给出n个pie的直径,有f+1个人,如果给每人分的大小相同(形状可以不同),每个人可以分多少.要求是分出来的每一份必须出自同一个pie,也就是说当pie大小为3,2,1,只能分出两个大小为 ...
- poj 3122(二分查找)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13564 Accepted: 4650 Special Ju ...
随机推荐
- PAT 1076 Wifi密码
https://pintia.cn/problem-sets/994805260223102976/problems/994805262622244864 下面是微博上流传的一张照片:“各位亲爱的同学 ...
- [转帖].NET Core 2.0 是您的最好选择吗?
.NET Core 2.0 是您的最好选择吗? https://www.cnblogs.com/vipyoumay/p/7388371.html 1. NET Core 2.0 是您的最好选择吗? 1 ...
- [转帖]Gartner预测2019年全球IT支出将达到3.8万亿美元
Gartner预测2019年全球IT支出将达到3.8万亿美元 http://server.zhiding.cn/server/2019/0130/3115439.shtml 全球领先的信息技术研究和顾 ...
- 小程序的wx.onAccelerometerChange
https://www.2cto.com/kf/201802/724174.html(copy) 也许有人会问,小程序中都是竖直app形态,要横竖屏判断有什么用?即使判断出了横屏状态,你能把小程序横过 ...
- doc.update
db.collection('todos').doc('todo-identifiant-aleatoire').update({ // data 传入需要局部更新的数据 data: { // 表示将 ...
- html5 简介
html5基于html.html dom.xhtml的新版本. 为html5建立的一些新规则: 基于html.dom.xhtml和javascript: 减少对外部插件的需求,比如flash: 更多取 ...
- Java之JSON处理(JSONObject、JSONArray)
依赖包:json-20180130.jar MAVEN地址: <dependency> <groupId>org.json</groupId> <artifa ...
- codeforces469B
Chat Online CodeForces - 469B 问题描述 你和你的朋友经常在网上聊天.你的朋友作息规律每天只会在p个时间段[ai,bi]在线.你作息混乱,假设你在t时刻起床,那么你会在q个 ...
- 微软开放 6 万项 Linux 专利,有哪些是我们该注意的?
导读 上周,微软宣布正式加入 Open Invention Network (“OIN”) 社区,开放其 6 万多项 Linux 专利.消息一出,许多人疑惑微软为什么要这么做?作为普通开发者,是否能使 ...
- [转载]使用VS2015搭建Lua开发环境
参考原文请看: Lua学习笔记1:Windows7下使用VS2015搭建Lua开发环境(一) Lua学习笔记2:Windows7下使用VS2015搭建Lua开发环境(二) 本篇主要分以下几个部分: 一 ...