思路:

模拟。

实现:

 #include <bits/stdc++.h>
using namespace std;
const long long INF = ;
double dis(double x1, double y1, double x2, double y2)
{
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main()
{
int a, b, c;
double x1, x2, y1, y2;
while (cin >> a >> b >> c)
{
cin >> x1 >> y1 >> x2 >> y2;
if (a == || b == )
{
printf("%.10f\n", fabs(x1 - x2) + fabs(y1 - y2));
continue;
}
double n1 = x1, m1 = y2; // y1--y2
double ty = (-a * x1 - c) / b;
double tx = (-b * y2 - c) / a;
double ans = fabs(x1 - x2) + fabs(y1 - y2);
if (ty >= min(y1, y2) && ty <= max(y1, y2) && tx >= min(x1, x2) && tx <= max(x1, x2))
{
double tmp = fabs(y1 - ty) + fabs(x2 - tx) + dis(x1, ty, tx, y2);
ans = min(ans, tmp);
}
double ty2 = (-a * x2 - c) / b;
if (ty >= min(y1, y2) && ty <= max(y1, y2) && ty2 >= min(y1, y2) && ty2 <= max(y1, y2))
{
double tmp = fabs(y1 - ty) + fabs(ty2 - y2) + dis(x1, ty, x2, ty2);
ans = min(ans, tmp);
}
double n2 = x2, m2 = y1; // x1--x2
tx = (-b * y1 - c) / a;
ty = (-a * x2 - c) / b;
if (ty >= min(y1, y2) && ty <= max(y1, y2) && tx >= min(x1, x2) && tx <= max(x1, x2))
{
double tmp = fabs(x1 - tx) + fabs(y2 - ty) + dis(tx, y1, x2, ty);
ans = min(ans, tmp);
}
double tx2 = (-b * y2 - c) / a;
if (tx >= min(x1, x2) && tx <= max(x1, x2) && tx2 >= min(x1, x2) && tx2 <= max(x1, x2))
{
double tmp = fabs(x1 - tx) + fabs(tx2 - x2) + dis(tx, y1, tx2, y2);
ans = min(ans, tmp);
}
printf("%.10f\n", ans);
}
return ;
}

CF1079D Barcelonian Distance的更多相关文章

  1. Codeforces 1079D Barcelonian Distance(计算几何)

    题目链接:Barcelonian Distance 题意:给定方格坐标,方格坐标上有两个点A,B和一条直线.规定:直线上沿直线走,否则沿方格走.求A到B的最短距离. 题解:通过直线到达的:A.B两点都 ...

  2. Codeforces I. Barcelonian Distance(暴力)

    题目描述: In this problem we consider a very simplified model of Barcelona city. Barcelona can be repres ...

  3. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)

    题意:给出一条直线 ax +by+c=0  给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及   给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...

  4. Codeforces 1032 - A/B/C/D/E - (Undone)

    链接:http://codeforces.com/contest/1032/ 是真的真的真的忍不住想吐槽这题意是真的真的真的读不懂…… A - Kitchen Utensils - [简单数学题] 题 ...

  5. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution

    A. Kitchen Utensils Water. #include <bits/stdc++.h> using namespace std; #define N 110 int n, ...

  6. [LeetCode] Total Hamming Distance 全部汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  7. [LeetCode] Hamming Distance 汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  8. [LeetCode] Rearrange String k Distance Apart 按距离为k隔离重排字符串

    Given a non-empty string str and an integer k, rearrange the string such that the same characters ar ...

  9. [LeetCode] Shortest Distance from All Buildings 建筑物的最短距离

    You want to build a house on an empty land which reaches all buildings in the shortest amount of dis ...

随机推荐

  1. mac上Firefox安装firebug和firepath

    Firefox安装Selenium ide插件时提示:该附加组件无法安装 因为它似乎已损坏,如下图: 此时千万不要去想着这个插件有问题,可能是Firefox的版本问题. 在Firefox45之后的新版 ...

  2. Sense2vec with spaCy and Gensim

    如果你在2015年做过文本分析项目,那么你大概率用的是word2vec模型.Sense2vec是基于word2vec的一个新模型,你可以利用它来获取更详细的.与上下文相关的词向量.本文主要介绍该模型的 ...

  3. LWDB

    题意: 给一棵 $n$ 个节点的树,维护两种操作: 1.将距离 $x$ $distance \leq d$ 的点染成 $c$ 2.询问 $x$ 的颜色. 解法: 首先将染色可以转换为每个时间对应一个颜 ...

  4. Yet Another Number Sequence

    题意: $F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2}$ 求解$\sum_{i=1}^n{ F_i i^K } \  mod \  10^9+7$. 解法: 记$ ...

  5. 1、webpack课程介绍

  6. css 属性相关

    css属性相关 宽和高 width属性可以为元素设置宽度, height属性可以为元素设置好高度 块级标签才能设置宽度,内联标签的宽度由内容来决定. 字体属性 文字字体 font-family 可以把 ...

  7. HDU - 2036 改革春风吹满地 叉乘法求多边形面积

    改革春风吹满地 “ 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)” 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟 ...

  8. ASP.NET Core Web API + Angular 仿B站(三)后台配置 JWT 的基于 token 的验证

    前言: 本系列文章主要为对所学 Angular 框架的一次微小的实践,对 b站页面作简单的模仿. 本系列文章主要参考资料: 微软文档: https://docs.microsoft.com/zh-cn ...

  9. Lightoj 1094 【DFS】

    题意: 给你一颗n-1条边的树,求某两点的最长路 思路: 随便找个根,然后我们从根往下搜,对于每个结点会出现多个子节点或者一个子节点或者没有结点, 多个子节点的话,就以他为中间点,在子节点中找两条最长 ...

  10. Codeforces482B【线段树构造】

    题意: 有M个限制,每个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是否有满足的数列. 思路: 看到大牛说是线段树,线段树对于区间操作,印象中乘啊,+啊,-啊都不错,但是并没有就是 ...