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

要特别注意精度啊!!!!

Posted by 13408100238 at 2015-03-29 11:28:19 on Problem 1064
#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:
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