POJ1064

 #include <iostream>
#include <iomanip>
#include <cmath>
using namespace std; int N;
int K;
double num[]; int calc(double len)
{
int numK= ;
for(int i = ; i < N; ++i)
{
numK += (int)(num[i] / len);
}
return numK;
} double solve()
{
double low = ;
double upper = ;
int count = ;
double mid;
int numK;
while(count < )
{
mid = (low + upper) / ;
numK = calc(mid);
if(numK >= K)
low = mid;
else
upper = mid;
++count;
}
return mid;
} int main()
{
//基于二分法的思想实现
cin >> N >> K;
for(int i = ; i < N; ++i)
cin >> num[i];
//这里floor很重要
cout << setiosflags(ios::fixed) << setprecision() << floor(solve()*)/ << endl;
return ;
}
上一篇:用C语言实现中国象棋


下一篇:PHP慢脚本日志和Mysql的慢查询日志(转)