思路:

模拟。

实现:

 #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. POJ1904(有向图缩点+输入输出挂参考)

    King's Quest Time Limit: 15000MS   Memory Limit: 65536K Total Submissions: 8311   Accepted: 3017 Cas ...

  2. calico在docker上的部署及验证

    1. 背景 以下的部署以五台服务器环境为例: 服务器1: hostname为etcdnode1, IP为192.168.56.100 服务器2: hostname为etcdnode2, IP为192. ...

  3. Firebug 的脚本页面不能用

    1.遇到这种情况,一般重置firebug,然后开启“脚本“功能,刷新页面,就能显示正常 2.要不就是 版本问题,50.0不行,下载回49版本就可以了

  4. 20个Flutter实例视频教程-第13节: 展开闭合案例

    20个Flutter实例视频教程-第13节: 展开闭合案例 视频地址: https://www.bilibili.com/video/av39709290/?p=13 博客地址: https://js ...

  5. 怎么在const成员函数里面调用非const成员函数?

    举个例子: 定义了一个类的const实例,怎么让他也能调用非能调用非const成员函数class foo{public:void test1() {cout << "I am n ...

  6. Mybatis源码解读-设计模式总结

    虽然我们都知道有26个设计模式,但是大多停留在概念层面,真实开发中很少遇到,Mybatis源码中使用了大量的设计模式,阅读源码并观察设计模式在其中的应用,能够更深入的理解设计模式. Mybatis至少 ...

  7. Node.js 内置模块Stream(流)

    "流"是一种抽象的数据结构 通过使用"流"可以将一段数据分割成几段,并按顺序传输,使用"流"可以降低对系统性能的要求,减少对CPU的消耗 S ...

  8. 33、JSONP跨域

    跨域请求数据也是可以的,只不过Ajax这技术不行,而JSONP这种数据格式可以进行跨域.很多年前,浏览器是没有跨域限制的,可以正常跨域,浏览器为了安全和隐私限制了Ajax跨域 JSONP原理就是:将函 ...

  9. Java 执行linux命令(转)

    转自 http://blog.csdn.net/a19881029/article/details/8063758 java程序中要执行linux命令主要依赖2个类:Process和Runtime 首 ...

  10. 黑马MySQL数据库学习day01 安装多个版本MySQL mysqld.exe工具