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

去看看msdn看qsort的比较函数怎么写吧,还有(x+1)/2->x/2+1

Posted by frkstyc at 2005-09-02 23:47:01 on Problem 2370
In Reply To:难道是我错误理解题意了? Posted by:Gump at 2005-09-02 23:40:46
>     我的解题思路是先把输入的含有n个元素的数组a排序(从小到大),然后对前(n+1)/2个元素作如下的处理,
> s+= (a[i]+1)/2 。还请大牛指点迷津。
>      # include< iostream.h >
> # include< stdlib.h >
> int compare( const void *p, const void *q)
> {
> 	return *(int*)p > *(int*)q;
> }
> int main()
> {
> 	int a[101];
> 	int n,m,s=0;
> 	cin>>n;
> 	for( int i=0; i<n; i++ )
> 		cin>>a[i];
> 	qsort( a,n,sizeof( int ), compare );
> 	m= ( n+1 )/2;
> 	for( i=0; i<m; i++ )
> 		s+= ( a[i]+1 )/2;
> 	cout<<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