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

用 nth_element 做不是更好吗? 怎末wa 了 溢出也解决了啊

Posted by bean244 at 2009-08-14 08:23:50 on Problem 2623
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[250000];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)  scanf("%d",&a[i]);
    nth_element(a,a+n/2,a+n);
    if(n&1)   printf("%d.0\n",a[n/2]);
    else {
         nth_element(a,a+n/2,a+n/2);
         double ans = (double)1.0*(a[n/2-1]+a[n/2])/2;
         printf("%.1f\n",ans);
    }
//    system("pause");
}

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