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

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

What's wrong with test 22?
Послано xj.ammo 9 дек 2005 23:29
In test 22 P=Q
Suppose down=P*100 & up==Q*100
then the answer should be:
  if(down==up){
    for(b2=1;b2<10000;b2++)
    {
    if(up*b2%10000==0)
      break;
    }
    printf("%d\n",b2);
    return 0;
  }
but this doesn't work...
So I believe that there must be sth wrong.Please check it!
P < Q
Послано Vladimir Yakovlev (USU) 10 дек 2005 01:01
Re: P < Q
Послано xj.ammo 10 дек 2005 09:55
Then I don't believe that it satisfies the two digits precision. When I changed down=P*100 to down=P*1000 my prog got accepted.
Re: P < Q
Послано Pi-Horng Liu 10 дек 2005 13:59
I also had failed at the test case 22 due to Time Limit Exceeded; after I had seen this thread I changed my program from P*100 to P*1000 as xj.ammo did, I got Accepted too, and it means when I considered three digits after decimal instead of two, then P<Q in that case(because when P<Q, the only loop in my program will terminate within 100000(or 100001, I'm not sure) iterations, which is very quick in computers nowadays). Does it means the judge had the test case 22 precised down to three digits and in that case P and Q only differ in the third digit after decimal point?
Re: What's wrong with test 22?
Послано Ostap Korkuna (LNU) 12 дек 2005 16:29
Let me explain you the trick with the test #22.
When you have for example P = 30.55, then if you look at it in the Debugger you wiil see that it is represented as 30.549999 . So when you take only 2 decimal digits you will get 30.54 (which is incorrect). And if you take 3 digits you will have 30.549 and it will work.
P. S.: If P = 40.79 than for real you have 40.790001 .
Re: What's wrong with test 22?
Послано Tbilisi SU: Andrew Lutsenko 11 окт 2006 15:24
Why don't you just use round()?

Part of my AC program:

  read(pe,qe);
  p:=round(pe*100);
  q:=round(qe*100);
Re: What's wrong with test 22?
Послано Iskren Ivov Chernev 28 сен 2007 01:44
on C/C++ there is NOT a function
double round (double)
in math.h (I don't know why - it is in the standart), so you can use an epsilon for this purpose (you'll get an error only if pe == x.9999 which will be trunkated to x instead of x+1 => so just add 1e-9)
p = (int)(pe * 100 + 1e-9)
q = (int)(qe * 100 + 1e-9)
Re: What's wrong with test 22?
Послано scythe 17 янв 2012 01:54
Great tip from Ostap Korkuna (LNU).

use int or long long in your calculations + that tip = ACCEPTED