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

杭电和poj区别

Posted by 20114958 at 2012-08-14 11:27:16 on Problem 3122
相同的时间限制,相同的代码,杭电上AC而poj上竟然超时了!!!!!
而杭电上WA的代码poj上竟然AC了!!!!
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include <cstdlib>
#include<cmath>
#include<string.h>
using namespace  std;
double a[10009];
double pi=acos(-1.0);
int main()
{//杭电上AC而POJ上超时的代码
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,f;
        cin>>n>>f;
        f++;
        double min=0,max=0;
        for(int i=1;i<=n;i++)
        {
            int tem;
            scanf("%d",&tem);
            a[i]=pow(tem,2.0);
            //min=min<a[i]?min:a[i];
            max+=a[i];
        }

        double mid=(max+min)/2;
        int sum=0;
        //cout<<"aa"<<max<<"bb"<<mid<<endl;
        while((max-mid)>0.00000001)
        {//cout<<"ok"<<endl;
            sum=0;
            for(int i=1;i<=n;i++)
            {

               sum+=(int)(a[i]/mid);
            }

            if(sum>=f){min=mid;mid=(max+min)/2;}
            else{max=mid;mid=(max+min)/2;}
        }
        //cout<<sum<<endl;

        double s=mid*pi;
          printf("%.4lf\n",s);


    }
    return 0;

}
=======================
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include <cstdlib>
#include<cmath>
#include<string.h>
using namespace  std;
int a[10009];
double pi=acos(-1.0);
int main()
{//杭电上WA而POJ上AC的代码,,郁闷
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,f;
        cin>>n>>f;
        f++;
        double min=0,max=0;
        for(int i=1;i<=n;i++)
        {
             int tem;
            scanf("%d",&tem);
            a[i]=pow(tem,2.0);
            max+=a[i];
        }

        double mid=(max+min)/2;
        int sum=0;

        while((max-mid)>0.000001)
        {
            sum=0;
            for(int i=1;i<=n;i++)
            {
               sum+=(int)(a[i]/mid);
            }

            if(sum>=f){min=mid;mid=(max+min)/2;}
            else{max=mid;mid=(max+min)/2;}
        }


        double s=mid*pi;
          printf("%.4lf\n",s);


    }
    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