این مسابقه در تاریخ پنج شنبه ۱۴ دی به صورت حضوری در سایت دانشکده برق و کامپیوتر دانشگاه تهران برگزار شد.

I- Travel to Italy


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Amin grew tired of the cold and rainy winters in Tabriz. This year, he decided to spend his holidays in Italy, his home country, and to finally visit his favorite amusement park, Pizzalandia.

Pizzalandia, as seen from above, is a rectangle of X×YX \times Y meters (respectively XX meters horizontally and YY vertically). Its biggest attraction is without a doubt the Pizzatrain, which runs clockwise along the borders of the rectangle at a fixed speed of 1 meter per second.

Since Amin has already explored most of the park, he thinks it’s finally time for him to get on the train himself, which can be done simply by being on the border of the rectangle at the same second of the train.

He knows the current coordinates of the train, TxT_x and TyT_y, and he’s currently standing in coordinates Wx,WyW_x, W_y. Inside the park, it’s only possible to move horizontally or vertically.

Amin wants to get on the train quickly, but having noticed that today the park is very crowded, he decided that he would simply choose a direction, move in that direction at a speed of 1 meter per second, and then just wait for the train to reach his location.

Help Filippo by figuring out the minimum time it will take him to board the train with this strategy.

input🔗

This problem has multiple test cases. The first line contains TT, the number of test cases to solve.

Each of the following TT lines contains six integers: the horizontal and vertical lengths of Pizzalandia XX and YY , the Pizzatrain’s horizontal and vertical coordinates $𝑇_x$ and TyT_y, and finally Amin’s horizontal and vertical coordinates WxW_x and WyW_y.

1T10001 \leq T \leq 1000 1X,Y1091 \leq X, Y \leq 10^9 0TxX0 \leq T_x \leq X 0TyY0 \leq T_y \leq Y

  • The train is guaranteed to be (and stay!) on the border

0Wx<X0 \leq W_x \lt X 0Wy<Y0 \leq W_y \lt Y

output🔗

For each test case, you need to write a single line containing the minimum number of seconds it will take Amin to get on the train, by following his strategy of moving in only one direction.

example🔗

sample input 1🔗

1
7 6 4 6 3 4
Plain text

sample output 1🔗

5
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.