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 |
注意到了long long int结果还是WA了,是贪心算法思路不对吗#include<stdio.h> int l[20001]; int main() { //freopen("stat.in", "r", stdin); int n,i,j; long long int sum = 0; scanf("%d", &n); if (n == 1) { printf("%d\n",0); return 0; } for (i = 0; i < n; i++) { scanf("%d", &l[i]); } int t = 1, mi = 1; while ((mi*=2)<n) { t++; } if (mi == n) mi *= 2; for ( i = 0; i < n; i++) { for ( j = i+1; j < n; j++) { if (l[i]>l[j]) { int temp = l[i]; l[i] = l[j]; l[j] = temp; } } } for ( i = 0; i < mi/2; i++) { sum = sum + (l[i] * t); } for ( i = mi/2; i < n; i++) { sum = sum + (l[i] * (t-1)); } printf("%lld\n", sum); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator