HDU 1969 Pie(二分搜索)
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.
---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.
题解:将n个蛋糕分给m+1个人,但是每个人只能拿到一块(不能拼凑),每块大小要相同(形状不用相同),问每个人最多能分到多大的蛋糕(面积)。思路是先求出面积,用数组保存,并排序。L为0,R为最大的那个蛋糕的面积,然后二分搜索。
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
using namespace std;
//#define LOCAL
int n,m;
double a[];
bool check(double x)
{
int cnt=;
for(int i=; i<n; i++)
{
cnt+=int(a[i]/x);
if(cnt>=m)return ;
}
return ;
}
bool cmp(double a,double b)
{
return a>b;
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
int N;
cin>>N;
while(N--)
{
//int n,m;
cin>>n>>m;
m++;
ms(a);
for(int i=; i<n; i++)
{
cin>>a[i];
a[i]=a[i]*a[i]*PI;
}
sort(a,a+n,cmp);
double l=,r=a[],mid;
if(m<n)n=m;//即使前面m个不够,后面的也没用,这样可以省点时间
while(r-l>1e-)
{
mid=(r+l)/;
if(check(mid))l=mid;
else r=mid;
}
printf("%.4lf\n",l);
}
return ;
}
HDU 1969 Pie(二分搜索)的更多相关文章
- hdu 1969 Pie(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others) Me ...
- HDU 1969 Pie(二分法)
My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...
- 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 ...
- hdu 1969 Pie (二分法)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1969 Pie【二分】
[分析] “虽然不是求什么最大的最小值(或者反过来)什么的……但还是可以用二分的,因为之前就做过一道小数型二分题(下面等会讲) 考虑二分面积,下界L=0,上界R=∑ni=1nπ∗ri2.对于一个中值x ...
- 题解报告: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 ...
- HDU 1969 Pie
二分答案+验证(这题精度卡的比较死) #include<stdio.h> #include<math.h> #define eps 1e-7 ; double a[ff]; d ...
随机推荐
- NLog在MVC中使用
NLog在MVC中使用 在site根目录新建NLog.config <?xml version="1.0"?> <configuration> <nl ...
- Chapter 21_3 模式
很多地方都会看到各种匹配模式,每次接触这些函数,颇使人望文生畏. 今天就来好好面对它.认识它.了解它.最后战胜它. 匹配模式都是用一串常规的字符串来描述,最主要的是理解这些字符串的语法及含义(即它能匹 ...
- noip 2016 提高组总结(不是题解)
小弱鸡杨树辰是第一次参加像noip这样的高大上的比赛,于是他非常,非常,非常激动. 当他第二天考完试后,他正在yy自己的分数:day1T1应该是a掉了,T2写了个30分的暴力,T3也是个40分的暴力, ...
- QWebView 播放网络视频
最近想看某站的VIP视频,但是网络上的软件用着都不怎么习惯,还有些要收费(收费还不如买VIP了..),所以自己研究做个网络播放器,使用的是QWebView. 1.设置WebView ui->we ...
- CodeForces 78D Archer's Shot
二分. 统计过程如下图: 先统计红线上的个数,然后统计绿线上的个数,然后统计咖啡色线上的个数......一个一个往下统计就可以了. #pragma comment(linker, "/STA ...
- 工厂模式Assembly.Load(path).CreateInstance 反射出错解决办法
项目结构: DALFactory 反射代码反射 //使用缓存 private static object CreateObject(string AssemblyPath,string classNa ...
- Unity2D开发小细节
当某个触碰物体挂在父组件时,如果当前子组件不加rigidbody,会默认使用父组件的rigidbody
- HTML中<title>与<h1>区别
1)<title>标签表示的标题是整个网页的名字,即在浏览器顶部的tab栏里显示的.搜索引擎通过它来搜索网页:<title>标签里的文本不出现在页面内容里面. <h1&g ...
- Android Studio新手
目标:Android Studio新手–>下载安装配置–>零基础入门–>基本使用–>调试技能–>构建项目基础–>使用AS应对常规应用开发 AS简介 经过2年时间的研 ...
- HDOJ_就这么个烂题总是WA先放这把
#include<stdio.h> __int64 A[100]={0}; __int64 B[100]={0}; __int64 SUM[100]={0}; int main() {in ...