CF1032D.Barcelonian Distance

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In this problem we consider a very simplified model of Barcelona city.

Barcelona can be represented as a plane with streets of kind x=cx = c and y=cy = c for every integer cc (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Diagonal which can be represented as a the set of points (x,y)(x, y) for which ax+by+c=0ax + by + c = 0.

One can walk along streets, including the avenue. You are given two integer points AA and BB somewhere in Barcelona. Find the minimal possible distance one needs to travel to get to BB from AA.

本题中,我们考虑一个高度简化的巴塞罗那城市模型。

巴塞罗那可被表示为一个平面,其街道由所有形如 x=cx = c 和 y=cy = c 的直线构成(其中 cc 为任意整数),即一个矩形网格。然而,有一个细节使巴塞罗那区别于曼哈顿:存在一条名为“对角大道”(Avinguda Diagonal)的主干道,它可被表示为满足方程 ax+by+c=0ax + by + c = 0 的所有点 (x,y)(x, y) 构成的集合。

人们可以沿街道(包括该大道)行走。现给定巴塞罗那中的两个整数坐标点 AA 和 BB。求从 AA 出发到达 BB 所需的最短路径长度。

输入格式

The first line contains three integers aa, bb and cc (−109≤a,b,c≤109-10^9\leq a, b, c\leq 10^9, at least one of aa and bb is not zero) representing the Diagonal Avenue.

The next line contains four integers x1x_1, y1y_1, x2x_2 and y2y_2 (−109≤x1,y1,x2,y2≤109-10^9\leq x_1, y_1, x_2, y_2\leq 10^9) denoting the points A=(x1,y1)A = (x_1, y_1) and B=(x2,y2)B = (x_2, y_2).

第一行包含三个整数 aa、bb 和 cc(−109≤a,b,c≤109-10^9\leq a, b, c\leq 10^9,且 aa 与 bb 中至少有一个不为零),表示对角线大道。

下一行包含四个整数 x1x_1、y1y_1、x2x_2 和 y2y_2(−109≤x1,y1,x2,y2≤109-10^9\leq x_1, y_1, x_2, y_2\leq 10^9),表示点 A=(x1,y1)A = (x_1, y_1) 和 B=(x2,y2)B = (x_2, y_2)。

输出格式

Find the minimum possible travel distance between AA and BB. Your answer is considered correct if its absolute or relative error does not exceed 10−610^{-6}.

Formally, let your answer be aa, and the jury's answer be bb. Your answer is accepted if and only if ∣a−b∣max⁡(1,∣b∣)≤10−6\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}.

求 AA 与 BB 之间可能的最小旅行距离。若你的答案的绝对误差或相对误差不超过 10−610^{-6},则视为正确。

形式化地,设你的答案为 aa,评测组的答案为 bb。当且仅当 ∣a−b∣max⁡(1,∣b∣)≤10−6\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6} 时,你的答案被接受。

输入输出样例

  • 输入#1

    1 1 -3
    0 3 3 0

    输出#1

    4.2426406871
  • 输入#2

    3 1 -9
    0 3 3 -1

    输出#2

    6.1622776602

说明/提示

The first example is shown on the left picture while the second example us shown on the right picture below. The avenue is shown with blue, the origin is shown with the black dot.

第一个示例显示在左侧图中,第二个示例显示在下方右侧图中。大道用蓝色表示,原点用黑点表示。

输入解题思路,AI测评打分。不知道怎么写?

首页