ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1011. Кондукторы

To admins
Послано JIeHuH*CCCP 29 окт 2006 17:45
Dear admins,

Please pay attention to my message. Problem 1011. Are you sure with the test 17. My solution with the formula

  a: =-1;
  repeat
    inc (a);
  until (trunc (a*q-0.00000001)-trunc (a*p))> 0;

was WA at test #17, though I sure that it's true. After a chat reading I have corrected it

  a: =-1;
  repeat
    inc (a);
  until (trunc (a*q-0.0000000000000001)-trunc (a*p+0.0000000000000001))> 0;

, and it was AC, though I am sure, that it's wrong in math.

1)
------|p*a|-(k)-------------|q*a|------------(k+1)-------

p*a - [p*a] = 0.9999999999... {0. (9)}
and
[q*a-0] - [p*a] = 1 (> =1)

2)
0 = 0.000000000001
p*a + 0 - [p*a + 0] = 0 (become integer)
and
[q*a-0] - [p*a+0] = 0

PS: or it is just an Pascal accuracy error?

Edited by author 15.11.2006 04:27
Could admins give answer to me?
Послано JIeHuH*CCCP 15 ноя 2006 04:29
Re: Could admins give answer to me?
Послано Nechaev Ilya (Rybinsk SAAT) 15 ноя 2006 11:42
Try make solution that uses olny integers (except variables for reading input). So you will have no problems with precision. I got only WA's while using floating point ariphmetic (in C++ and Pascal), and AC while using integers.

Edited by author 15.11.2006 11:45
Re: Could admins give answer to me?
Послано JIeHuH*CCCP 20 ноя 2006 09:00
So "a" is integer (you cannot use inc with real)
"trunc (a*q-0.00000001)" and "trunc (a*p)" are int too
Re: To admins
Послано Nechaev Ilya (Rybinsk SAAT) 20 ноя 2006 17:24
You don't understand me.
Use something like this for reading input:

double p1, q1;
int p, q;
..............
scanf("%lf%lf", &p1, &q1);
p = floor(p1*100+0.5);
q = floor(q1*100+0.5);

And in your solution don't use p1, q1, and any other floating point variables and operations at all.

Edited by author 20.11.2006 17:26
Re: "...don't use p1, q1, and any other floating point variables..."
Послано JIeHuH*CCCP 21 ноя 2006 04:48
Nechaev Ilya (Rybinsk SAAT) писал(a) 20 ноября 2006 17:24

p = floor(p1*100+0.5);
q = floor(q1*100+0.5);

why are you using +0.5 with p1 and q1??? IMHO it's not fare and it's false.

Edited by author 21.11.2006 04:49
Re: To admins
Послано Daniel Ampuero 5 дек 2006 21:22
You could also do the follow thing:
int p, q;
scanf("%d.%d", &p, &q);
where p is the integer part of the number and q is the rational part of the number. (sorry for the bad english...)