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

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

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

include<stdio.h>

include<math.h>

int main(){

int a,t,i;

double y,z;

scanf("%d",&t);

for(i = 0; i < t; i++){

    scanf("%d",&a);

    if(a == 1){

        printf("N\n");
    }
    else{
        y = ((double)a + sqrt((double)a*(double)a - 4*(double)a))/2;

        z = ((double)a - sqrt((double)a*(double)a - 4*(double)a))/2;

        printf("Y %0.9lf %0.9lf\n",y,z);
    }
}
return 0;

why this code shows wrong answer(1076 C)

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by zarif_2002 (previous revision, new revision, compare).

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

The problem solution has three cases:

  1. if d = 0, then the answer is Yes, and a = b = 0.

  2. if d = 1, 2, or 3, then the answer is No.

  3. if d > 3, then the answer is Yes, a = c (1+e) and b = c (1-e), where c = d/2 and e = sqrt(1-2/c).

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It is because you do not check if discriminant is lower then zero, but check if a==1 instead. And if D is equal to zero, you should output only one root (actually there will be two same roots).

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

In this problem you literally have to solve a + b = d, a * b = d when d is given. The resulting equation after substituting ( for example b = d — a ) into the second equation will be -a^2 + ad — d = 0 ( a quadratic equation ), it has no solutions for real numbers when a * a — 4 * a < 0.