Go to diff to previous submission
#include <stdio.h> /*#include <math.h>*/ double ah(double n) { return (n<0)?-n:n; } int main(){ int L,A,maxL,maxR,mid,mid2; double L2; int p,i; char c; /*struct { }Pole[100000];*/ L2=(L-1)/2.0; maxL=maxR=mid2=-1; if(c=='R') maxR=p; else maxL=p; mid=p; for(i=2;i<=A;++i){ if(c=='R'){ if(p<maxR) maxR=p; }else{ if(p>maxL) maxL=p; } if(ah(p-L2)<ah(mid-L2)){ mid=p; mid2=-1;} else if(ah(p-L2)==ah(mid-L2)) mid2=p; } //printf("%d%d%d\n",maxL,maxR,L); if(maxL==-1){ mid=maxR; }else if(maxR==-1){ mid=maxL; } maxL=(maxL>maxR)?maxL:(L-maxR); } return 0; }
--- c4.s1259.cteam125.ants.c.0.ant.c +++ c4.s1327.cteam125.ants.c.0.ant.c @@ -16,5 +16,5 @@ }Pole[100000];*/ while(scanf("%d%d",&L,&A)!=EOF){ - L2=L/2.0; + L2=(L-1)/2.0; scanf("%d%1s\n",&p,&c); maxL=maxR=mid2=-1; @@ -40,5 +40,5 @@ mid=maxL; } - maxL=(maxL>maxR)?maxL:(L-maxR); + maxL=(maxL>maxR)?maxL:(L-maxR); printf("The last ant will fall down in %d seconds - started at %d",maxL,mid); if(mid2!=-1) printf(" and %d.\n",mid2);