문제출처 : https://www.acmicpc.net/problem/20115
code
#include <stdio.h> #include <stdlib.h> void QuickSort(int arr[],int start,int end) { if (start > end) return; int piv = start, left = start + 1, right = end, temp; while (left <= right) { while (left <= end && arr[left] >= arr[piv]) left++; while (right > start && arr[right] <= arr[piv]) right--; if (left > right) { temp = arr[right]; arr[right] = arr[piv]; arr[piv] = temp; } else { temp = arr[right]; arr[right] = arr[left]; arr[left] = temp; } } QuickSort(arr, start, right - 1); QuickSort(arr, right + 1, end); } int main() { int N, i; int* x; double sum = 0; scanf("%d", &N); x = (int*)malloc(N * sizeof(int)); for (i = 0; i < N; i++) scanf("%d", &x[i]); QuickSort(x, 0, N - 1); sum = x[0]; for (i = 1; i < N; i++) sum += (double)x[i] / 2; printf("%.1lf", sum); free(x); return 0; }
코드는 엄청쉽다. 다만 출력조건에 절대/상대오차는 무슨뜻인지 잘모르겠다...