Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一定要用floor函数,不然是4舍5入啊.

Posted by zhanglanqing at 2016-02-15 16:27:57 on Problem 1064
#include<iostream>
#include<stdio.h>
#include<math.h>
#define N 10000+7
using namespace std;
int n,k;
double a[N];
bool can(double x)
{
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        cnt+=int(a[i]/x);
    }
    if(cnt<k)return false;
    else return true;
}
int main()
{
    freopen("/home/zlq/QTACMING/in","r",stdin);
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        double m=-1;
        for(int i=0;i<n;i++)
        {
            scanf("%lf",&a[i]);
            if(a[i]>m){m=a[i];}
        }
        double l=0,r=m,mid;
        int cnt=0;
        while(r-l>1e-4)
        {

            mid=(l+r)/2;
            if(can(mid))
            {
                l=mid;
            }
            else
            {
                r=mid;
            }
            cnt++;
        }
        printf("%.2f\n",floor(l*100)/100);//如果不加floor函数是四舍五入
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator