Error with test cases

Asked

Viewed 56 times

1

My teacher recommended this site called Uri, and I’m managing to solve some issues, only that in this tried all the solutions that the question posed and the program that I made out the requested results in the question, the judge Uri is giving 30% error but 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;
}

1 answer

1

There is no reason to look for the height of the biggest pipe. Doing this implies that you did not understand the problem properly. The only thing that matters is the difference between the heights of the pipes. The absolute value of each pipe does not matter. The difference between a pipe of height 5 and a pipe of height 7 is the same as between a barrel of height 10005 and a barrel of height 10007. Thus, it is not for you to compare the height of the barrel to the height of the frog’s jump, because even if you have a 1000-height pipe and the frog has jump height equal to 2, it is still correct if the next pipe is 1001 and the previous 999.

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

In doing so:

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

You are checking the difference in heights between a pipe in odd position of the pipe in even position that follows. However, this does not check the height between the pipe’s even position in the subsequent odd position. No reason to separate even pipe heights from odd pipe heights (vetorc and vetorb). It would be so much easier to do that:

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

However, this code may eliminate the need to use the vetorf when making the verification within the for:

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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.