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 |
看 我的第一次 greedy haha ACIn Reply To:我是这样过的,供参考 Posted by:t9thkid at 2006-05-26 21:16:00 #include<stdio.h> #include<stdlib.h> int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } void main() { int n, num, a[1002], i; scanf("%d",&n); while(n--) { scanf("%d",&num); __int64 total = 0; for(i = 0;i < num;i++) scanf("%d",&a[i]); qsort(a, num, sizeof(a[0]), cmp); for(i = num - 1;i >= 3;i -= 2) { if(2 * a[1] >= a[0] + a[i - 1]) total += 2 * a[0] + a[i - 1] + a[i]; else total += 2 * a[1] + a[0] + a[i]; } if(i == 2)total += a[0] + a[1] + a[2]; if(i == 1)total += a[1]; if(i == 0)total += a[0]; printf("%ld\n",total); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator