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 lqplsw2009 at 2009-12-17 15:29:15 on Problem 1064
#include <iostream>
using namespace std;
int n;
int main()
{
    int k,i,j,num=0;
    bool sign=1;
    int test(float array[],float x);
    float sum=0;
    float a[10005]={0},l;
    while(scanf("%d%d",&n,&k)!=EOF)
{
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    l=sum/k;
    if(l<0.01)
    sign=0;
    else
    num=test(a,l);
    for(;num<k&&sign==1;)
    {
        l-=0.01;
        if(l<0.01)
        {
            sign=0;
            break;
        }

        num=test(a,l);
    }
    if(sign==0)
    printf("0.00\n");
    else
    printf("%.2f\n",l);
    return 0;
}
}
int test(float array[],float x)
{
    int i,z=0;
    for(i=0;i<n;i++)
    z+=array[i]/x;
    return z;
}

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