Skip to content

Instantly share code, notes, and snippets.

@henryyang42
Created February 27, 2014 16:22
Show Gist options
  • Save henryyang42/9253412 to your computer and use it in GitHub Desktop.
Save henryyang42/9253412 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
int N ,Test,i,avg,sum ,total,n_num,num[2000000];
double x ,y;
int main()
{
scanf("%d",&Test);
while(Test--){
scanf("%d",&N);
sum=0;
for(i=0;i<N;i++){
scanf("%d",&num[i]);
sum+=num[i];
}
//avg = (float)sum/(float)N;
x = (float)sum/(float)N;
avg = (int)x;
y = x - avg ;
if(y>=(0.5))
avg++;
else
avg=avg;
//printf("%d\n",avg);
//printf("%f\n",y);
total = 0;
for(i=0;i<N;i++){
n_num = avg-num[i];
n_num = n_num*n_num;
total+=n_num;
//printf("%d\n",n_num);
//printf("%d\n",total);
}
printf("%d\n",total);
}
return 0 ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment