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坐标至少有一个整点的时 以及 给出的直线才有路径(也就是格子坐标图的线上)
问 两个整点所需要经过的最短距离
思路: 整点和整点之间的最短路径 要么 经过 直线 要么不经过直线 如果不经过直线,那么最短距离就是两者的曼哈顿距离 |x1-x2|+|y1-y2|
如果经过线段 那么一个点有两种到线段的方式 一种是和线段上的点x 相同 一个是和线段上的点y相同 2*2一共四种情况 全部算一遍取最小即可
还要考虑斜率等于0以及直线垂直x轴的情况
#include<bits/stdc++.h>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define mkp make_pair
#define all(zzz) (zzz).being(),(zzz).end()
typedef long long ll;
using namespace std;
const int maxn=1e5+;
double dist(double x1,double y1,double x2,double y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main(){
ll a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
ll x1,y1,x2,y2;
scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
double ans=abs(x2-x1)+abs(y2-y1);
if(a!=&&b!=){
double x3=x1;
double y3=1.0*(-c-a*x1)/b;
double y4=y1;
double x4=1.0*(-c-b*y1)/a;
double x5=x2;
double y5=1.0*(-c-a*x2)/b;
double y6=y2;
double x6=1.0*(-c-b*y2)/a;
ans=min(dist(x3,y3,x5,y5)+abs(y3-y1)+abs(y5-y2),ans);
ans=min(dist(x4,y4,x5,y5)+abs(x4-x1)+abs(y5-y2),ans);
ans=min(dist(x3,y3,x6,y6)+abs(y3-y1)+abs(x6-x2),ans);
ans=min(dist(x4,y4,x6,y6)+abs(x4-x1)+abs(x6-x2),ans);
}
else if(a==&&b!=){
ans=min(ans,dist(x1,-c/b,x2,-c/b)+abs(-c/b-y1)+abs(-c/b-y2));
}
else if(a!=&&b==){
ans=min(ans,dist(-c/a,y1,-c/a,y2)+abs(-c/a-x1)+abs(-c/a-x2));
}
printf("%.10lf\n",ans);
return ;
}
Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)的更多相关文章
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano
题意:给出一个数列 a1 a2......an 让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i) 那么b( ...
- 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, ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path
http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)
https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】
任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...
随机推荐
- DSAPI 字符串和文件转Md5字符串
方法列表: 字符串转MD5字符串(ByVal 要转换的字符串 As String, Optional 转换格式 As MD5格式 = MD5格式.小写32位) As String 文件转MD5字符串( ...
- 用于ViEmu的重置为试用状态的Python脚本
import winreg import shutil shutil.rmtree("C:\\Users\\Administrator\\AppData\\Local\\Identities ...
- WPF 自定义 ImageButton
控件源码: public class ImageButton : Button { public ImageButton() { } public string No ...
- jQuery(四)、文档处理
1 内部插入 1.1 append(content | fn) 向每个匹配的元素内部追加内容. 参数: (1) content:要追加到目标中的内容. (2) function(index, html ...
- css文字超出一行用点表示
1,css超出一行用点表示 white-space:nowrap; overflow:hidden; text-overflow:ellipsis; 2,css超出二行用点表示 overflow:hi ...
- MongoDB学习(操作集合中的文档)
文档概念 文档的数据结构和JSON基本一样. 所有存储在集合中的数据都是BSON格式. BSON是一种类json的一种二进制形式的存储格式,简称Binary JSON. 插入文档 insert()方法 ...
- 可以让你神操作的手机APP推荐 个个都是爆款系列
手机在我们的生活中显得日益重要,根据手机依赖度调查显示,69%的人出门时必带手机,20%的人经常在吃饭睡觉.上卫生间时使用手机:43%的人早上起床第一件事就是查看手机,不用多说,我们对于手机的依赖性越 ...
- Android为TV端助力 外挂字幕(设置颜色,大小,位置,微调字幕)
前提摘要: 可以给电影加字幕,目前支持srt和ass格式, 功能摘要: 支持微调字幕,设置大小,颜色,位置 1 .字幕解析类 package com.hhzt.iptv.lvb_x.utils; ...
- 数据结构学习java(一点五)链式顺序表(链表)
java中没有将指针暴露给用户(以前做过看过一篇文章写有java中是有指针的,只是被藏起来了),所以得使用引用的方式. 何为引用请看下面这篇文章(写的很不错,当然肯定比我写的好): https://w ...
- 手把手教新手小白在window把自己的项目上传到github
作为一个开发者,写博客,上传项目到github好像是不可不会的技能,很多有经验的老司机都会这么建议你.本宝宝第一次要把项目传到github的时候,确实有点蒙蔽,什么鬼,传个东西有必要这么难吗? git ...