Pie[二分]
来源:互联网 发布:保险退保现金价值算法 编辑:程序博客网 时间:2024/06/13 02:13
题意:过生日大家分饼吃?m+1个人分饼,每个人要分一样的面积(高度为1),饼可以切但是不能拼。问最大能人均多少。
思路:二分面积就好啦。先算出每个饼的面积,由于check需要O(n)复杂度,所以套一层二分面积就好。
二分的单调性: 如果能够均分每人得到S的饼,那么对于任意的
二分的 check(mid):对于给定的均分量mid,看每个饼能出几份,然后加起来看是否大于等于m+1即可。
#include<iostream>#include<string>#include<cstdio>#include<cstring>#include<bitset>#include<algorithm>#include<map>#include<set>#include<queue>#include<vector>#include<cstdlib>#include<list>#include<stack>#include<cmath>#include<iomanip>using namespace std;//#pragma comment(linker, "/STACK:1024000000,1024000000")typedef long long LL;void debug() {cout << "ok running!" << endl;}const double PI = acos(-1.0);int n, m;double a[10005];bool check(double x){ int sum = 0; for(int i = 0; i < n; ++i) sum += (int)(a[i]/x); if(sum >= m) return 1; else return 0;}int main(){ ios::sync_with_stdio(false); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif // ONLINE_JUDGE int t; cin >> t; while(t--) { cin >> n >> m; m++; for(int i = 0; i < n; ++i) { int x; cin >> x; a[i] = x*x*PI; } //cout << a[0] << endl; double l = 0, r = 10005*10005*PI; double ans = -1; while(r - l > 0.000001) { //cout << l << " " << r << endl; double mid = (l+r)/2; //cout << mid << endl; if(check(mid)) { ans = mid; l = mid; } else r = mid; } ios::fixed; //cout << ans << endl; cout << fixed << setprecision(4) << ans << endl; } return 0;}
阅读全文
0 0
- Pie(二分)
- 【二分】Pie
- Pie (二分)
- Pie 【二分】
- Pie 二分
- Pie[二分]
- hdu pie(二分+贪心)
- POJ 3122 Pie 二分
- POJ 3122 Pie 二分
- hdu1969 Pie 二分
- POJ3122--Pie--二分
- hdu1969(pie二分)
- [hoj]Pie【二分】
- HDU1969---Pie 二分
- HDU1969:Pie(二分)
- [二分]HDOJ1969 Pie
- 二分查找 hdu1969 pie
- hdu1969 Pie 二分
- 2018网易校招_堆棋子_C++
- HashMap,ConcurrentHashMap与LinkedHashMap的区别
- 微信测试号——scope参数错误或没有scope权限
- 【Python】Python3 List append()方法
- Matlab plot函数详解
- Pie[二分]
- 银行管理系统(控制台版),数据库用mysql
- java的简易科学计算器的实现
- 林学——安徽四旁树占地面积折算标准
- Python数据挖掘与机器学习_通信信用风险评估实战(3)——特征工程
- som9331 构建最小根文件系统
- 青岛往事
- 第一到第三范式与查询 思考
- 正则表达式技术详解 Regular Expression