搜索算法 problem(1003)
来源:互联网 发布:网络技术交流论坛 编辑:程序博客网 时间:2024/06/06 00:25
1.简单题意
有f+1个人分n块披萨,每个人要求分得的面积一样,且披萨只能被切开而不能重新组合,求每个人能分到的最大面积v
2.解题思路
对于每个确定的v,可以计算出最多能满足的人数p。因此得到一个单调递减的函数关系,并且v的范围也可以确定为0~max(size(i)),i=1...n。
3.AC代码
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>#include<iostream>using namespace std;const double pi = acos(-1.0);double a[10005];int n, m;int check(double mid){ int i; int sum = 0; for (i = 0; i<n; i++) { sum += int(a[i] / mid); if (sum >= m) return 1; } return 0;}int cmp(double a, double b){ return a>b;}int main(){ int t, i; double l, r, mid; cin>>t; while (t--) { cin >> n >> m; m++; for (i = 0; i<n; i++) { cin >> a[i]; a[i] = a[i] * a[i] * pi; } sort(a, a + n, cmp); l = 0; r = a[0]; if (m<n) n = m; while (r - l>1e-5) { mid = (r + l) / 2; if (check(mid)) l = mid; else r = mid; } printf("%.4lf\n", l); } return 0;}
0 0
- 搜索算法 problem(1003)
- 搜索算法 problem(1001)
- 搜索算法 problem(1002)
- 搜索算法 problem(1013)
- 搜索算法 problem(1014)
- 搜索算法 problem(1008)
- 搜索算法 problem(1005)
- 搜索算法 problem(1017)
- 搜索算法 problem(1009)
- 搜索算法-二分搜索-方程解问题(problem 1001)
- 搜索算法-二分搜索-方程解问题(problem 1002)
- Problem G: 逃脱(搜索)
- 1016 Prime Ring Problem 搜索(深搜)
- Prime Ring Problem(搜索 深度优先)
- HDU1016 - Prime Ring Problem (简单搜索)
- 区间搜索(算法)
- 搜索算法(poj1011)
- 搜索算法-二分搜索(折半查找)
- POJO
- 笔试题36. LeetCode OJ (23)
- Thrift源码剖析
- 用sql语句写入含blob类型字段的数据
- 102. Binary Tree Level Order Traversal
- 搜索算法 problem(1003)
- OKHttp使用总结
- Thrift异步IO服务器源码分析
- 第四章 二分查找(数组)
- 专题二 Problem1014
- spring mvc 上传文件
- 电脑硬盘修复方法
- String hdoj 5672(字符串追赶)
- PAT (Advanced Level) Practise 1107. Social Clusters (30) 并查集