Pie(二分)
http://poj.org/problem?id=3122
题意:将n个圆柱体的不同口味的pie分给m个人,要求每个人分得的pie必须体积相同,且来自于一块pie(即:只分得一种口味的pie),求最多每个人可分得的体积。
思路:理解了题意就好做了,二分并注意精度。
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;
const double PI=acos(-1.0);
const double eps=1e-;//设置精度
const int N=;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,num;
double pie[N],maxn = ,r;
scanf("%d %d",&n,&num);
num++;
for (int i = ; i < n; i++)
{
scanf("%lf",&r);
pie[i] = r*r;//每个pie代表的体积(暂时不乘π)
maxn = max(maxn,pie[i]);
}
double mid;
double low = ;//下限
double high = maxn;//上限为按最大的那块分
while(high-low>eps)//二分
{
mid = (high+low)/;//每次以体积mid尝试着分
int cnt = ;
for (int i = ; i < n; i++)
{
cnt+=(int)pie[i]/mid;//统计可以分的人数
}
if (cnt < num)//如果可以分的人数比原人数少,说明以mid分的体积过大
high = mid;//减少上限
else
low = mid;//增加下限
}
printf("%.4f\n",mid*PI);
}
return ;
}
Pie(二分)的更多相关文章
- HDU 1969 Pie(二分查找)
Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no ...
- HDU 1969 Pie(二分,注意精度)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 【POJ 3122】 Pie (二分+贪心)
id=3122">[POJ 3122] Pie 分f个派给n+1(n个朋友和自己)个人 要求每一个人分相同面积 但不能分到超过一个派 即最多把一整个派给某个人 问能平均分的最大面积 二 ...
- Pie(二分POJ3122)
Pie Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12985 Accepted: 4490 Special Ju ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- 【hoj】2651 pie 二分查找
二分查找是一个非常主要的算法,针对的是有序的数列,通过中间值的大小来推断接下来查找的是左半段还是右半段,直到中间值的大小等于要找到的数时或者中间值满足一定的条件就返回,所以当有些问题要求在一定范围内找 ...
- HDU1969:Pie(二分)
Pie Time Limit : 5000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- B - Pie (二分)
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...
- UVaLive 3635 Pie (二分)
题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...
随机推荐
- html table内容不随标题滚动
<html><head></head><body> <div> <div id="demo" style=&quo ...
- js弹开页面并调用方法
每次重新写一个功能的时候,都能发现以前写的并不太好,都可以改进,奇怪的是我还是我,为什么曾经的我就想不起来要这么写,比如下面两段代码 历史代码: if (infoTablePage != null) ...
- pandas.DataFrame.quantile
pandas.DataFrame.quantile 用于返回数据中的 处于1/5 1/2(中位数)等数据
- Optimizing web servers for high throughput and low latency
转自:https://blogs.dropbox.com/tech/2017/09/optimizing-web-servers-for-high-throughput-and-low-latency ...
- 浅谈 extern "C"
今天上课实在无聊,就看了看 extern "C" 的作用,看了以后对它有了一点点理解,在这里给大家分享一下(本菜鸡水平有限,如若有说得不对的地方,还望大家指出). extern 关 ...
- python中enumerate( )函数的使用
enumerate( )函数是遍历一个序列中的元素以及元素对应的下标 seq = ['one', 'two', 'three'] for i, element in enumerate(seq): p ...
- [luogu2591 ZJOI2009] 函数
传送门 Solution 画图找规律.. Code //By Menteur_Hxy #include <cstdio> #define min(a,b) ((a)>(b)?(b): ...
- Centos 7 关闭firewall防火墙启用iptables防火墙
一.关闭firewall防火墙 1.停止firewall systemctl stop firewalld.service 2.禁止firewall开机启动 systemctl disable fir ...
- 一次vue-cli 2.x项目打包优化经历(优化xlsx插件)
一.分析各模块打包后大小 用vue-cli创建的项目,已经集成 webpack-bundle-analyzer.详见文件 build/webpack.prod.conf.js,代码如下: if (co ...
- Django REST framework - 视图
目录 Django REST framework 视图GenericAPIView GenericAPIView 例子 属性 混入 具体视图类 自定义基类 Django REST framework ...