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

Общий форум

please help me , i need your help ; i have a problem that i can not resolve but it is not from this site
Послано GoGo 17 авг 2001 22:55
My name is Calin Ciutu and i am from Romania. I am 16 years
old , i study at the National College of Informatics . One
of my friends send my an e-mail with a problem (a very hard
one (for me) ) . After 2 weeks of thinking i am trying to
find some one who can give me an idea .

Here is the problem if you can help me somehow :

Imagine a building with 40000 floors numberd from 0 up to
39999 .
In this builing the lifts doesn't work  .
You receive some commands (not more then 5000) from your
superiors : to get a package from floor i (0<=i<40000) to
carry it to floor j(0<=j<40000).
Very nervous you take all the commands and write them
down : every command is codifyed with 2 numbers i and j (i
means the floor from where you have to take the package and
j means the floor where you have to take the package).

You have to use the stairs. To go up 1 floor is very hard
so it costs you 1 calorie , but to go down one or more
floors it doesn't costs you nothing.
The goal is to take all the packages to them destination
with a minimum cost of calories.
At the start you are at the floor numbered with "0" . You
can carry only 1 package at a time . The order in witch you
take the packages to them destinations doesn't matter . You
can take a package from his source , drop it at another
floor and after some time come and take it from here to
another floor or to it's destination .

INPUT: "input.txt"
-the first line of the input contains a number: n -> the
 number of commands
-the next n lines each contains a pair of numbers separated
 by a single space ("i j") witch means : i (0<=i<40000) =
 the floor from where to take a package and j (0<=j<40000)=
 the floor where you have to drop the package .

OUTPUT: "output.txt" ->!attention! you have to find only
the minimum cost of calories to take all packages to them
destination not the way to do it with a minimum cost
-one line containing the minimum cost of calories to take
 all packages to them destination

Sample Input

input.txt:
3
1 3
2 4
6 5

Sample Output

output.txt
7
-------
{you go from 0 to 1 (1 calorie) ; you take the first
package to 2 (1
calorie) you drop it and you take the second package to 3
where you drop
it(1 calorie) ; you go down to 2 (0 calories) you take the
first package to
his destination (3) (1 calorie) here you find the second
package and you
take it to his destination (4) (1 calorie) ; now you go to
6 (2 calories)
and take it to his destination (5) (0 calories) ; so the
total is : 7
calories (there is many other modes to take the packages
with 7 calories :
0->1->3->2->4->6->5)}

Plese help me .

   calin ciutu
  zotax@home.ro