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

Обсуждение задачи 1286. Космолёт марки ВАЗ

AC :) (+)
Послано Yu Yuanming 16 май 2005 20:54
A maths problem......

First, let m = x2 - x1, n = y2 - y1, d:= gcd(p, q) {assume p, q > 0, this is no harm but convenient}

Second, discuss four trivial case:
  1. (m = 0) and (n = 0) {Y}
  2. (p = 0) and (q = 0) {N}
  3. (p = 0) or (q = 0)  {Y / N}
  4. (m mod d <> 0) or (n mod d <> 0) {N}

Third, make p = p / d, q = q / d, m = m / d, n = n / d

Fourth, find x and y so that p * x + q * y = 1.
Let A1 = x * m , B1 = y * m
    A2 = y * n , B2 = x * n
You job is to judge whether there exist k1 and k2 so that
(A1 + A2 + k1 * p + k2 * q ) and (B1 + B2 + k1 * q + k2 * p) are both even numbers, if so, output 'YES', otherwise 'NO'.
By the way, just check (k1 = 1, 2) and (k2 = 1, 2) are enough...

I have proved my algo is right.
Anyway, if you doubt whether it is right, you could try to prove or disprove it by yourself, too.
If you have another algo,I will be pleased if you could write it down.

Sorry for my bad English, hope it can help :)

Edited by author 16.05.2005 21:01
Something easier.
I did almost the same, but...
1) I didn't care about p=0 or q=0
2) I didn't cate about p<0 or q<0
So, I assumed that (p>0) and (q>0) - it seemed so evident from the problems's situation (-:

And after having divided everything by gcd, I do the following:
if p mod 2 + q mod 2 = 1
then (* p is even and q is odd or vice versa *)
___Result := true
else (* both p and q are odd *)
___Result := ( deltaX + deltaY ) mod 2 = 0
______(* we can reach a point iff its coords are both even or odd at the same time *)

And I got AC. http://acm.timus.ru/status.aspx?space=1&pos=903260
Something more easier.
Послано Fly [Yaroslavl_SU] 10 окт 2005 03:05
I use:
if( Abs( Abs( DI - SI ) - Abs( DJ - SJ ) ) % NOD( Abs( P - Q ), 2 * nod_pq ) != 0 )
____Result = false;
Re: Something more easier.
Послано Alex Stoff 19 окт 2005 22:28

Sorry, but what does it mean:
1) DI
2) SI
3) DJ
4) SJ
5) NOD( Abs( P - Q ), 2 * nod_pq )!=Factorial(GCD(abs(p-q),2*qcd(p,q)))