http://www.codechef.com/JAN11/problems/FLUSHOT/
*m getting wrong answer*
*if there is any problem wid my algorythm do let me know*
#include<stdio.h>
> int main()
{
int t,D,N,j,i;
float T,*x,*y,*z,maxNo,minNo;
scanf("%d",&t);
while(t--)
{
scanf("%d %f",&N,&T);
x=(float*)malloc(sizeof(float)*(N+1));
y=(float*)malloc(sizeof(float)*(N+1));
z=(float*)malloc(sizeof(float)*(N+1));
for(i=0;i<N;i++)
{
scanf("%f",&x[i]);
}
if((x[1]+x[0])<=T || x[0]==0)
{
maxNo=x[0];
for(i=1;i<N;i++)
{ x[i]-=i*T;
if(x[i]<0)
x[i]=-x[i];
if(x[i]>maxNo)
maxNo=x[i];
}
}
else
{ maxNo=0.0;
j=0;
for(i=0;i<N;i++)
{
y[i]=x[i]-(x[0]+i*T);
if(y[i]<0)
{ z[j]=-y[i];}
if(y[i]>maxNo)
{ maxNo=y[i];}
if(z[j]>minNo && j!=0 &&y[i]<0)
{ minNo=z[j];}
if(y[i]<0)
{j++;}
if(j==1 &&y[i]<0)
{minNo=z[0];}
}
if(N==2)
maxNo=maxNo/2;
else maxNo=(maxNo+minNo)/2;
}
printf("%.4f\n",maxNo);
}
return 0;
}
--
Sanchit Mittal
Second Year Undergraduate
Department of Computer Engineering
Delhi College of Engineering
ph- +919582414494
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.