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

float -->double 就过了,

Posted by ajioy at 2011-07-25 11:04:21 on Problem 2623
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}

int main()
{
    int num[250001];
    int n,i;
    double ans;//float 过不了 
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    	scanf("%d",num+i);
    }
    qsort(num,n,sizeof(int),cmp);
    
    if(n%2==0)
    {
    	ans=num[n/2]/2.0+num[n/2-1]/2.0;//(double)(num[n/2]+num[n/2-1])/2.0 也无法过,括号中的加法运算是在int范围内进行的,在进行double强制类型转换之前的int两个int类型相加可能超出int类型的范围 
    }
    else
    {
    	ans=num[n/2];
    }
    printf("%.1lf",ans);
    

}

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