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

改了一下你的代码就AC了

Posted by Sempr at 2006-05-05 14:05:14 on Problem 2388
In Reply To:求助 我用nth_element() 为什么 不行 请帮忙 老Wa Posted by:goldenking at 2006-05-05 13:48:29
注意C语言里,数组的下标是从0开始的,a[5]这个数组中的中间元素是a[2],不是a[3].

Source

Problem Id:2388  User Id:Sempr 
Memory:116K  Time:76MS
Language:C++  Result:Accepted

Source 

#include<iostream>
#include<fstream>
#include<algorithm>
#define MAXN 10000
using namespace std;
int main()
{
   
   long int milk[MAXN], N;
   long int result;
   int i;
   while(cin>>N)
   {
	   for(i=0;i<N;i++)
		   cin>>milk[i];
	   result=N/2;
	   nth_element(milk, milk + result, milk + N);
	   cout<<milk[result]<<endl;
   }
   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