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

二分做这题TLE有毒!

Posted by 13100855098 at 2016-04-25 13:58:06 on Problem 3111
改了两个地方就AC,一个是 把排序的定义方式cmp写成结构体里对<的重载
bool cmp(node a,node b)
{
    return a.b>=b.b;
}
改成:
struct node
{
    double b;int t;
    bool operator<(const struct node&a)const//重载运算符
    {
        return b>a.b;
    }
}a[100000+10];

还有吧二分精度写成1e-6次方,开始我写的都是for(int i=0;i<100;i++){}
  for(int i=0;i<100;i++){
           double mid=(l+r)*0.5;
           if(check(mid)) l=mid;
           else r=mid;
  }
  改成:
  while(r-l>=1e-6){
           double mid=(l+r)*0.5;
           if(check(mid)) l=mid;
           else r=mid;
        }

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