Help! Can anyone point out why my program got WA on test 5?
Posted by
Dragon 18 Feb 2005 08:05
#include <stdio.h>
#include <stdlib.h>
#define infile "1288.in3"
#define outfile "1288.ou3"
#define maxn 10100
#define zero 1e-6
double a[maxn+1],xs;
long n,d,front,back,s[3],e[3],l[3];
FILE *fin=stdin,
*fout=stdout;
void init()
{
long i;
fscanf(fin,"%ld%ld",&n,&d);
for (i=1; i<=2; i++)
fscanf(fin,"%ld%ld%ld",&s[i],&e[i],&l[i]);
fscanf(fin,"%lf",&xs);
for (i=1; i<=n; i++)
fscanf(fin,"%lf",&a[i]);
fclose(fin);
}
void find_front_wall()
{
long i,you=0;
for (i=1; i<=n; i++)
if (a[i]<=35+zero)
you=1;
else if ((a[i]>=95-zero)&&(you))
{
front=i;
return;
}
fprintf(fout,"No surface.\n");
fclose(fout);
exit(0);
}
void change()
{
long i;
for (i=front+1; i<=n; i++)
a[i]=a[i]*(1+(i-front+0.0)*xs);
}
long find_back_wall()
{
long i,you=0;
if (front+d>n)
return 0;
for (i=front+1; i<front+d; i++)
if (a[i]<=35+zero)
you=1;
for (i=front+d; i<=n; i++)
if (a[i]<=35+zero)
you=1;
else if ((a[i]>=95-zero)&&(you))
{
back=i;
return 1;
}
back=n+1; //special!!!
return 0;
}
long min(long a,long b)
{
if (a<b)
return a;
else return b;
}
void zhao(long sign,long s,long e,long l)
{
long i,j;
if (front+s>back-1)
{
fprintf(fout,"Channel %ld: No search.\n",sign);
return;
}
s=front+s;
e=min(front+e,back-1);
j=s;
for (i=s; i<=e; i++)
if (a[i]>a[j]+zero)
j=i;
if (a[j]>l-zero)
fprintf(fout,"Channel %ld: Object at %ld.\n",sign,j-front);
else fprintf(fout,"Channel %ld: No object.\n",sign);
}
void work()
{
find_front_wall();
change();
fprintf(fout,"Surface found at %ld.\n",front);
if (find_back_wall())
fprintf(fout,"Bottom found at %ld.\n",back-front);
else fprintf(fout,"No bottom.\n");
zhao(1,s[1],e[1],l[1]);
zhao(2,s[2],e[2],l[2]);
fclose(fout);
}
int main()
{
init();
work();
return 0;
}