Hoj 2653 Pie
来源:互联网 发布:阿里云与华为 编辑:程序博客网 时间:2024/04/29 00:15
本题练习二分法:
题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=2651
分析:对于每个确定的没人分得的面积v,可以计算出最多能满足的人数p。因此得到一个单调递减的函数关系,并且v的范围也可以确定为0~max(size(i)),i=1...n。
由于精度差问题,考虑先将面积*1000000转化为整数来二分
#include <iostream>#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;//pi的精度尽可能大#define pi 3.14159265358979323846long long size[10005];int t;int n,f;int s = 1000000;bool judge(long long piece){ int p = 0; for(int i=0;i<n;i++) { p += size[i]/piece; } return p>=f;}int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif long long l,r; long long res; scanf("%d",&t); while(t--) { l = 1; res = 0; scanf("%d %d",&n,&f); f++; for(int i=0;i<n;i++) { scanf("%lld",&size[i]); size[i] = size[i] * size[i] * pi * s; if(size[i]>r) { r = size[i]; } } r += 1; while(l<=r) { long long mid = (l + r)>>1; if(judge(mid)) { l = mid + 1; res = mid; } else { r = mid -1; } } printf("%.4lf\n",(double)res/s); } return 0;}
- Hoj 2653 Pie
- HOJ 2651 PIE
- [hoj]Pie【二分】
- 【hoj】2651 pie 二分查找
- HOJ 2651 || POJ 3122 Pie
- hoj 2651 Pie(二分)hoj 2278 (二分)
- HOJ 2615 Pie ---------------二分查找的运用
- Hoj 2421 Hie with the Pie
- (简单) 状态压缩dp HOJ 2421 Hie with the Pie
- Pie
- Pie
- pie
- Pie
- Pie
- PIE
- Pie
- Pie
- Pie
- POJ 2318(点集二分)
- request.getParameter()和request.getAttribute()的返回值
- 图像工作回顾之二:摄像机标定
- opencdn部署说明
- 修改hostname
- Hoj 2653 Pie
- mythTV分析——简介 .
- Bash Shell-使用内置的set和shopt命令设置bash选项
- 简单的爬取网站
- 错误集_ nib文件加载,Unknown class <XXClass> in Interface Builder file.,Undefined symbolsfor architecture
- matlab GUI之一个例子
- 选择设计类培训学校的那些事儿
- POJ1988 Cube Stacking [并查集]
- solr高级