Source code for submission s1259

Go to diff to previous submission

ant.c

  1. #include <stdio.h>
  2. /*#include <math.h>*/
  3.  
  4. double ah(double n)
  5. {
  6. return (n<0)?-n:n;
  7. }
  8.  
  9. int main(){
  10. int L,A,maxL,maxR,mid,mid2;
  11. double L2;
  12. int p,i;
  13. char c;
  14. /*struct {
  15.  
  16.   }Pole[100000];*/
  17. while(scanf("%d%d",&L,&A)!=EOF){
  18. L2=L/2.0;
  19. scanf("%d%1s\n",&p,&c);
  20. maxL=maxR=mid2=-1;
  21. if(c=='R')
  22. maxR=p;
  23. else
  24. maxL=p;
  25. mid=p;
  26. for(i=2;i<=A;++i){
  27. scanf("%d%1s\n",&p,&c);
  28. if(c=='R'){
  29. if(p<maxR) maxR=p;
  30. }else{
  31. if(p>maxL) maxL=p;
  32. }
  33. if(ah(p-L2)<ah(mid-L2)){ mid=p; mid2=-1;}
  34. else if(ah(p-L2)==ah(mid-L2)) mid2=p;
  35. }
  36. //printf("%d%d%d\n",maxL,maxR,L);
  37. if(maxL==-1){
  38. mid=maxR;
  39. }else if(maxR==-1){
  40. mid=maxL;
  41. }
  42. maxL=(maxL>maxR)?maxL:(L-maxR);
  43. printf("The last ant will fall down in %d seconds - started at %d",maxL,mid);
  44. if(mid2!=-1) printf(" and %d.\n",mid2);
  45. else printf(".\n");
  46. }
  47. return 0;
  48. }

Diff to submission s1219

ant.c

--- c4.s1219.cteam125.ants.c.0.ant.c
+++ c4.s1259.cteam125.ants.c.0.ant.c
@@ -35,4 +35,9 @@
     }
     //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);
     printf("The last ant will fall down in %d seconds - started at %d",maxL,mid);