Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用sort(a,a+n);就行了~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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator