C - Get-Together at Den's

神  精度问题,好题

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 110;
double eps = 1e-5;

int A[N];

int main() {
	int n;
	while(scanf("%d", &n) != EOF) {
		double total = 0;
		for(int i = 0; i < n; ++i) {
			scanf("%d", &A[i]);
			total += A[i];
		}
		double sum = 0;
		double drink = (total / (n + 1));
		for(int i = 0; i < n; ++i) {
			if(A[i] > drink) sum += A[i] - drink;
		}
		for(int i = 0; i < n; ++i) {
			if(i) printf(" ");
			if(A[i] > drink) printf("%d", (int)(100.0 * (A[i] - drink) / sum + eps));
			else printf("0");
		}
		printf("\n");
	}
	return 0;
}

你可能感兴趣的:(C - Get-Together at Den's)