CF1079D Barcelonian Distance
思路:
模拟。
实现:
#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的更多相关文章
- Codeforces 1079D Barcelonian Distance(计算几何)
题目链接:Barcelonian Distance 题意:给定方格坐标,方格坐标上有两个点A,B和一条直线.规定:直线上沿直线走,否则沿方格走.求A到B的最短距离. 题解:通过直线到达的:A.B两点都 ...
- Codeforces I. Barcelonian Distance(暴力)
题目描述: In this problem we consider a very simplified model of Barcelona city. Barcelona can be repres ...
- 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坐标至少有一个整点的时 以及 给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...
- Codeforces 1032 - A/B/C/D/E - (Undone)
链接:http://codeforces.com/contest/1032/ 是真的真的真的忍不住想吐槽这题意是真的真的真的读不懂…… A - Kitchen Utensils - [简单数学题] 题 ...
- 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, ...
- [LeetCode] Total Hamming Distance 全部汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] Hamming Distance 汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [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 ...
- [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 ...
随机推荐
- js中this 的四种用法
this 在函数执行时,this 总是指向调用该函数的对象.要判断 this 的指向,其实就是判断 this 所在的函数属于谁. 在<javaScript语言精粹>这本书中,把 this ...
- AtCoder Regular Contest 063 E:Integers on a Tree
题目传送门:https://arc063.contest.atcoder.jp/tasks/arc063_c 题目翻译 给你一个树,上面有\(k\)个点有权值,问你是否能把剩下的\(n-k\)个点全部 ...
- java面试编程题
[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? //这是一个菲波拉契数列问 ...
- Mogodb 存储DateTime问题
由于mogodb默认用的是国际日期utc和中国时间有8小时时差. c#当中利用特别属性来解决,如: /// <summary> /// 创建日期 /// < ...
- Kefa and Watch
题意: 维护一个长度为n的字符串,两种操作: 1.将 [l,r] 的字符变为 c 2.询问 d 是否为 $S(l,r)$ 的周期 解法: 首先分析如何令 [l,r] 的周期为d,利用循环串的性质得: ...
- C#操作cmd
C#经常操作CMD,使用的话就用下面的2和3进行整理一下使用吧. 1.简单的调用命令不需要回传数据,最简单 public static void ipcmd(object p) { Process p ...
- 深入探究Java中equals()和==的区别是什么
目录 相等判断符"==" "=="判断基本类型数据 "=="判断引用类型数据 相等判断方法equals() 思考:为什么要设计equals( ...
- E20190324-hm
splice vt. 绞接; 捻接(两段绳子); 胶接; 粘接(胶片.磁带等); n. 胶接处,粘接处,铰接处;
- VC中使用GDI+实现为按钮加载Png图片
http://blog.csdn.net/flyfish1986/article/details/5381605 VC中使用GDI+实现为按钮加载Png图片 http://www.codeprojec ...
- 【渗透测试】如何使用burpsuite对特殊密码进行爆破
爆破是渗透测试中必不可少的一部分,对于没有太大价值可利用的漏洞或是业务只有一个登陆页面时,爆破更是我们的最合适的选择.那么在爆破时,抛去目标系统对爆破频率的限制,如果遇到较为复杂的密码,该如何顺利进行 ...