Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя alkos

Автор alkos, история, 9 лет назад, По-английски

i was trying a february challenge problem on the codechef here is the link to the problem https://www.codechef.com/FEB16/problems/DEVLDISC . I tried the problem for three days and i came to this logic. even after satisfying all the conditions mentioned it is still showing wrong answer. can anyone tell me what's wrong with this approach. while(t--){ scanf("%d",&n);

if(n%2)  {
       if(n <= 6)  printf("-1\n");
       else {
         int val = ceil(double(n-2)/2);
         printf("%d\n",n-1);
           for(int i = 1 ; i <= n - 2  ;i ++){
            printf("%d %d\n",i,i+1);
           }
            printf("1 %d\n",n-1);
            printf("%d %d\n",val + 3 ,n);
            printf("1\n");
       }
    }
    else {
       if(n <= 8)      printf("-1\n");
       else {
       printf("%d\n",n-1);
       for(int i = 1 ; i <= n - 2  ;i ++){
         printf("%d %d\n",i,i+1);
       }
       printf("1 %d\n",n-1);
       printf("6 %d\n",n);
       printf("%d\n" , 8 + (n - 10)/2);
       }
    }
}

Полный текст и комментарии »

  • Проголосовать: нравится
  • -47
  • Проголосовать: не нравится