103751: [Atcoder]ABC375 B - Traveling Takahashi Problem

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:16 Solved:0

Description

Score : $150$ points

Problem Statement

Takahashi is at the origin on a two-dimensional coordinate plane.

The cost for him to move from point $(a, b)$ to point $(c, d)$ is $\sqrt{(a - c)^2 + (b - d)^2}$.

Find the total cost when he starts at the origin, visits $N$ points $(X_1, Y_1), \ldots, (X_N, Y_N)$ in this order, and then returns to the origin.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $-10^9 \leq X_i, Y_i \leq 10^9$
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$
$X_1$ $Y_1$
$\vdots$
$X_N$ $Y_N$

Output

Print the answer.
Your output will be considered correct if its absolute or relative error from the true value is at most $10^{-6}$.


Sample Input 1

2
1 2
-1 0

Sample Output 1

6.06449510224597979401

The journey consists of the following three steps:

  • Move from $(0, 0)$ to $(1, 2)$. The cost is $\sqrt{(0 - 1)^2 + (0 - 2)^2} = \sqrt{5} = 2.236067977...$.
  • Move from $(1, 2)$ to $(-1, 0)$. The cost is $\sqrt{(1 - (-1))^2 + (2 - 0)^2} = \sqrt{8} = 2.828427124...$.
  • Move from $(-1, 0)$ to $(0, 0)$. The cost is $\sqrt{(-1 - 0)^2 + (0 - 0)^2} = \sqrt{1} = 1$.

The total cost is $6.064495102...$.


Sample Input 2

7
-14142 13562
-17320 50807
-22360 67977
24494 89742
-26457 51311
28284 27124
31622 77660

Sample Output 2

384694.57587932075868509383

Sample Input 3

5
-100000 100000
100000 -100000
-100000 100000
100000 -100000
-100000 100000

Sample Output 3

1414213.56237309504880168872

Output

得分:150分

问题陈述

高桥位于二维坐标平面的原点。

他从点$(a, b)$移动到点$(c, d)$的成本是$\sqrt{(a - c)^2 + (b - d)^2}$。

求他从原点出发,按顺序访问$N$个点$(X_1, Y_1), \ldots, (X_N, Y_N)$,然后返回原点的总成本。

约束条件

  • $1 \leq N \leq 2 \times 10^5$
  • $-10^9 \leq X_i, Y_i \leq 10^9$
  • 所有输入值都是整数。

输入

输入从标准输入以下格式给出:

$N$
$X_1$ $Y_1$
$\vdots$
$X_N$ $Y_N$

输出

打印答案。
如果您的输出的绝对误差或相对误差与真实值的误差最多为$10^{-6}$,则您的输出将被认为是正确的。


示例输入1

2
1 2
-1 0

示例输出1

6.06449510224597979401

旅程包括以下三个步骤:

  • 从$(0, 0)$移动到$(1, 2)$。成本是$\sqrt{(0 - 1)^2 + (0 - 2)^2} = \sqrt{5} = 2.236067977...$。
  • 从$(1, 2)$移动到$(-1, 0)$。成本是$\sqrt{(1 - (-1))^2 + (2 - 0)^2} = \sqrt{8} = 2.828427124...$。
  • 从$(-1, 0)$移动到$(0, 0)$。成本是$\sqrt{(-1 - 0)^2 + (0 - 0)^2} = \sqrt{1} = 1$。

总成本是$6.064495102...$。


示例输入2

7
-14142 13562
-17320 50807
-22360 67977
24494 89742
-26457 51311
28284 27124
31622 77660

示例输出2

384694.57587932075868509383

示例输入3

5
-100000 100000
100000 -100000
-100000 100000
100000 -100000
-100000 100000

示例输出3

1414213.56237309504880168872

Sample Input Copy


Sample Output Copy


加入题单

上一题 下一题 算法标签: