Error with test cases

1

My teacher recommended this site called uri, and I am able to solve some questions, but in that I tried all the solutions that the question put and the program I did comes out the results requested in the question, the uri judge is giving 30% of error but I do not know how to correct the error.

Link to the question.

Here is my code.

#include <stdio.h>

int main(void)
{
  int teste, altura, i, maior;
  scanf("%d %d", &altura, &teste);
   int vetor[teste], vetorb[teste], vetorc[teste], c = 0, b = 0, 
   vetorf[teste];
   for(i = 0; i < teste; i++)
   {
     scanf("%d", &vetor[i]);
   }
   for(i = 0; i < teste; i++)
   {
      if(i % 2 == 0)
      {
         vetorc[c++] = vetor[i];
      }
      else
      {
        vetorb[b++] = vetor[i];
      }

   }
   for(i = 0; i < c + b; i++)
   {
     vetorf[i] = vetorb[i] - vetorc[i];
   }
   maior = vetorf[0];
   for(i = 0; i < b; i++)
   {
     if(vetorf[i] > maior)
     {
        maior = vetorf[i];
     }
   }
   if(maior > altura)
   {
      printf("GAME OVER\n");
   }
   else
   {
     printf("YOU WIN\n");
   }
  return 0;
}
    
asked by anonymous 14.01.2018 / 21:26

1 answer

1

There is no reason to look for the height of the largest pipe. Doing so suggests that you did not get the problem right. The only thing that matters is the difference between pipe heights. The absolute value of each pipe does not matter. The difference between a barrel of height 5 and one of height 7 is the same as between a barrel of height 10005 and one of height 10007. Thus, it is not for you to compare the height of the barrel with the height of the frog's leap, if you have a barrel of height 1000 and the frog has jump height equal to 2, it is still correct if the next barrel has height 1001 and the previous bar 999.

You declare multiple vectors: vetor , vetorb , vetorc and vetorf . Only one would be enough.

When you do this:

for(i = 0; i < c + b; i++)
{
  vetorf[i] = vetorb[i] - vetorc[i];
}

You are checking the difference in heights between a barrel in the odd position of the barrel in the next pair. However, this does not check the height between the even position barrel of the barrel in the subsequent odd position. There is no reason to separate the heights of even pipes from odd pipe heights (% with% and% with%). It would be much easier to do this:

for (i = 0; i < teste - 1; i++) {
    vetorf[i] = vetor[i] - vetor[i + 1];
}

However, this code can eliminate the need to use vetorc when checking inside vetorb :

for (i = 0; i < teste - 1; i++) {
    int dif = vetor[i] - vetor[i + 1];
    if (dif < 0) dif = -dif;
    if (dir > altura) {
        printf("GAME OVER\n");
        return 0;
    }
}
printf("YOU WIN\n");
return 0;
    
15.01.2018 / 00:06