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

Обсуждение задачи 1261. Чаевые

it seems so easy but can't solve it;
Послано Dulat_TKTL 30 янв 2006 15:14
I tried many times
Please help!!!!!!
Re: it seems so easy but can't solve it;
Послано Sid 1 фев 2006 23:35
I don't remember exactly, I've solved this problem more than a year ago... But as I ramember it's easy to solve it if transform the numer in base of 3 format.

P.S. Sorry for my poor english.
Re: it seems so easy but can't solve it;
Послано Dulat_TKTL 2 фев 2006 14:15
must we use array
Re: it seems so easy but can't solve it;
Послано Michael Rybak (accepted@ukr.net) 3 фев 2006 19:05
I did.
Re: it seems so easy but can't solve it;
Послано Aybek_TKTL 3 фев 2006 19:58
how?
Michael Rybak (accepted@ukr.net) писал(a) 3 февраля 2006 19:05
I did.
Re: it seems so easy but can't solve it;
Послано Michael Rybak (accepted@ukr.net) 3 фев 2006 21:50
simply pre-generate all numbers that are sums of different powers of 3:

1. array <- 0
2. for item in array: array <- 3 + item
3. for item in array: array <- 9 + item
4. for item in array: array <- 27 + item
5. for item in array: array <- 81 + item
 ...
 until current power of 3 becomes larger than N * 3 + 1 (so it works for N = 1).

You should prove that there's no use to check any powers of 3 that are larger than N * 3 + 1. Use the fact that 1 + 3 + 9 + 27 + .. + 3 ^ k = 3 ^ (k + 1) / 2, which means that no number in interval (3^k / 2, 3^k - 1) can be represented in that fashion.

P.S. Note that the generated array will be sorted already, so no need to perform a sorting