网络赛前10奖励计蒜客的本子或鼠标垫(外校也可以来现场领取)
Xidian Online Judge WebBoard
[ New Thread ]
Problem 1013 >> Why TLE?
07126038 @ 2015-05-03 19:13:16
[ Quote ] [ Edit ] [ Delete ] 1#
I debuged it,and there is no endless loop on my code。Is my arithmetic too slow or other question?
please help me,thank you very much!

#include <stdio.h>
int main()
{
long int n,i,l,r,m,j,sum=0;
long long sum1=0;
int avg,k;

while(scanf("%ld",&n) != EOF)
{
int h[n];
for(i=0;i<n;i++)
{
scanf("%d",&h[i]);
}
scanf("%ld",&m);
for(j=0;j<m;j++)
{
scanf("%ld %ld %d",&l,&r,&k);
for(i=l;i<r;i++)
{
h[i]=h[i]-k;
}
}
for(i=0;i<n;i++)
{
sum+=h[i];
}
avg=(int)((float)sum/n);
for(i=0;i<n;i++)
{
sum1=sum1+(h[i]-avg)*(h[i]-avg);
}
printf("%I64d\n",sum1);
}
return 0;
}
xry111 @ 2015-05-03 19:25:38
[ Quote ] [ Edit ] [ Delete ] 2#
Certainly your algorithm is too slow.
[Top] [Previous Page] [Next Page]
Anything about the Problems, Please Contact Admin:admin
All Copyright Reserved 2010-2014 Xidian ACM Online Judge TEAM
GPL2.0 2003-2014 HUSTOJ Project TEAM