POJ 3122 Pie (二分+精度问题)
来源:互联网 发布:查看1433端口是否打开 编辑:程序博客网 时间:2024/06/18 11:49
题目地址:POJ 3122
思路还是二分,只是需要考虑一下精度问题,π要先不加,放到判断的时候再加上可以增加精度。
代码如下:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL __int64#define pi acos(-1.0)const int mod=9901;const int INF=0x3f3f3f3f;const double eqs=1e-4;LL v[20000];bool Judge(double f1, double f2){ return f2-f1>eqs;}double bin_search(int n, int m){ double low=0, high=4e8, mid, ans; int cnt; while(Judge(low,high)){ mid=(low+high)/2; cnt=0; for(int i=0;i<n;i++){ cnt+=(int)(v[i]*pi/mid); } if(cnt>=m){ ans=mid; low=mid+eqs; } else high=mid-eqs; } return ans;}int main(){ int t, n, m, i, r; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); m++; for(i=0;i<n;i++){ scanf("%d",&r); v[i]=r*r; } printf("%.4f\n",bin_search(n,m)); } return 0;}
0 0
- POJ 3122 Pie (二分+精度问题)
- POJ 3122-Pie(二分+精度)
- POJ 3122 Pie (二分+精度)
- poj3122--Pie(二分的精度问题)
- POJ 3122 Pie 二分
- POJ 3122 Pie 二分
- poj 3122 Pie (二分)
- Pie - POJ 3122 二分
- POJ 3122 Pie(二分)
- POJ 3122pie(二分)
- POJ 3122 pie 二分
- [poj 3122] Pie 二分
- POJ Pie 3122 (二分)
- POJ 3122 - Pie(二分)
- poj 3122 pie(二分搜索)
- poj 3122 Pie 二分答案
- POJ 3122 Pie【二分答案】
- poj 3122&&hdu1969 Pie(二分)
- 【php】截取中文字符串
- uva 10720 Graph Construction
- 规避重复包含
- AJAX and testing
- 时钟周期/指令周期/机器周期/指令周期
- POJ 3122 Pie (二分+精度问题)
- UVa 213 信息编码!模拟!
- KMP字符串匹配算法
- Selenium
- redis入门到精通
- android基础--2
- WebAii - tools for Ajax
- HDU2101 A + B Problem Too【水题】
- PCB之创建焊盘