uvalive 3635 - Pie(二分搜索)
2013-08-31 16:31
477 查看
题目连接:3635 - Pie
题目大意: 有m个派, 要分给n + 1个人, 要求每个人拿到的大小相同, 并且每个人的派必须是一整块, 不能说分别从两个派切出一块凑成。 现在给出m个派的半径(派均为圆柱,高为1),输出每人可以拿到的最大派的体积。
解题思路:二分查找。
题目大意: 有m个派, 要分给n + 1个人, 要求每个人拿到的大小相同, 并且每个人的派必须是一整块, 不能说分别从两个派切出一块凑成。 现在给出m个派的半径(派均为圆柱,高为1),输出每人可以拿到的最大派的体积。
解题思路:二分查找。
#include <stdio.h> #include <string.h> #include <math.h> const int N = 10005; const double pi = 4 * atan(1.0); int n, m; double L, R, mid, r ; bool judge (double cur) { int cnt = n; double now; for (int i = 0; i < m; i++) { now = r[i]; while (now - cur > 0) { now -= cur; cnt--; } if (cnt <= 0) return true; } return false; } int main() { int cas; scanf("%d", &cas); while (cas--) { // Init; R = 0, L = N * N; memset(r, 0, sizeof(r)); // Read; scanf("%d%d", &m, &n); for (int i = 0; i < m; i++) { scanf("%lf", &r[i]); r[i] = r[i] * r[i]; R += r[i]; if (L > r[i]) L = r[i]; } // Handle; n++; L /= n; while (fabs(R - L) >= 1e-4) { mid = (R + L) / 2; if (judge(mid)) L = mid; else R = mid; } printf("%.4lf\n", mid * pi); } return 0; }
相关文章推荐
- uvalive 3635 - Pie(二分搜索)
- UVALive 3635 Pie 【二分】
- UVALive 3635 Pie 切糕大师 二分
- UVALive - 3635 Pie(二分答案查找)
- UVALive - 3635 Pie 二分
- UVALive - 3635 - Pie(二分)
- 【UVALive3635】Pie(浮点二分)
- UVALive 3635 Pie (二分)
- UVALive3635 UVA12097 POJ3122 HDU1969 Pie【二分查找】
- UVaLive 3635 Pie (二分)
- UVALive 3635 Pie 切糕大师 二分
- UVALive 3635-Pie-二分
- UVALive 3635 Pie 二分查找
- 例题1.13 派 Pie UVALive - 3635 二分
- UVALive - 3635 Pie
- UVALive 6168 Fat Ninjas --二分小数+搜索
- UVALive 3635 Pie(二分法)
- uva 12097 Pie(二分搜索)
- UVALive - 3635 Pie
- Uva-Live Archive-3635-Pie