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

Обсуждение задачи 1333. Джинн-бомбардировки 2

Doubts about using the random number.
Послано MYLS 25 фев 2014 23:03
In my programme, I use 1000 000 random locations to check if the points are in the circle.
At first, I wrote something like this: "double tx = ( double )( rand() % 101 ) / 100.0 ";(because: 0 ≤ x ≤ 1, -> rand() % 101 ∈[ 0, 100 ] );and just got WA......
Finally I changed the 101 into 100 and got AC;
Can anyone tell me why 101 is incorrect? or it is actually right?
Re: Doubts about using the random number.
Послано Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 25 фев 2014 23:42
You're just lucky that in the second case you got AC - actually good tests will kill your second solution as well, because what you generate is random point on integer grid 100 x 100 and this is far from random real point.

Good way of generating random point in unit square is doing double(rand()) / RAND_MAX for both coordinates - this will give you point close enough to truly random.
Re: Doubts about using the random number.
Послано MYLS 1 авг 2014 12:29
Thanks for your reply, I realize I have mixed up continuity and dispersion. :-)