| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
要特别注意精度啊!!!!#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
using namespace std;
const int INF=0x4fffffff;
const int EXP=1e-6;
const int MS=10005;
int N,K;
double len[MS];
bool judge(double x)
{
int cnt=0;
for(int i=1;i<=N;i++)
cnt+=(int)(len[i]/x+EXP);
return cnt>=K;
}
void solve()
{
double l=0.0,r=MS*10.0;
double mid;
for(int i=0;i<100;i++)
{
mid=(l+r)/2;
if(judge(mid))
l=mid;
else
r=mid; // 注意这里是double。
}
printf("%.2lf\n",floor(mid*100)/100);
// 千万注意精度
// printf("%.2lf\n",mid); WA
}
int main()
{
scanf("%d%d",&N,&K);
for(int i=1;i<=N;i++)
scanf("%lf",&len[i]);
solve();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator