码迷,mamicode.com
首页 > 其他好文 > 详细

HDU1969

时间:2015-10-20 16:34:19      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

记得用PI=acos(-1)反三角函数求,用一次排序,然后二分和贪心

#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
class Pie{
public:
double r;
double s;
};
bool Check(Pie p[], int n, int f, double x);
bool Cpm(Pie&a, Pie&b){
return a.r>b.r;
}
int main(){
Pie p[10001];
int i, n, f, Case;
double left, right, mid, pi =acos(-1);
cin >> Case;
while (Case--){
cin >> n >> f;
f++;
for (i = 0; i < n; i++){
cin >> p[i].r;
p[i].s = p[i].r*p[i].r*pi;
}
sort(p, p + n, Cpm); //按面积从小大大排序
left = 0.0, right = p[0].s; //左右边界
while (right - left>1e-5){
mid = (left + right)/2;
if (Check(p, n, f, mid))
left = mid;
else
right = mid;
}
cout <<setiosflags(ios::fixed)<<setprecision(4)<<(left+right)/2<< endl;
}
return 0;
}
bool Check(Pie p[],int n,int f, double x){//检查是否可以满足条件
int i = 0, peo = 0;
for (i = 0; i < n; i++){
peo += int(p[i].s / x);
if (peo >=f)
return 1;
}
return 0;
}

HDU1969

标签:

原文地址:http://www.cnblogs.com/td15980891505/p/4895174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!