当前位置:网站首页>365天挑战LeetCode1000题——Day 043 有效的正方形 数学
365天挑战LeetCode1000题——Day 043 有效的正方形 数学
2022-07-29 11:43:00 【ShowM3TheCode】
593. 有效的正方形

代码实现(自解)
class Solution {
private:
const double epsilon = 0.00001;
public:
bool validSquare(vector<int>& p1, vector<int>& p2, vector<int>& p3, vector<int>& p4) {
if (p1 == p2 || p2 == p3 || p3 == p4) return false;
double p1p2 = sqrt(pow(p1[0] - p2[0], 2) + pow(p1[1] - p2[1], 2));
double p1p3 = sqrt(pow(p1[0] - p3[0], 2) + pow(p1[1] - p3[1], 2));
double p1p4 = sqrt(pow(p1[0] - p4[0], 2) + pow(p1[1] - p4[1], 2));
double p2p3 = sqrt(pow(p2[0] - p3[0], 2) + pow(p2[1] - p3[1], 2));
double p2p4 = sqrt(pow(p2[0] - p4[0], 2) + pow(p2[1] - p4[1], 2));
double p3p4 = sqrt(pow(p3[0] - p4[0], 2) + pow(p3[1] - p4[1], 2));
// p1,p2 is against
if (p1p3 == p1p4 && p2p3 == p2p4 && p1p3 == p2p3) {
return abs(p1p3 * sqrt(2) - p1p2) <= epsilon;
}
// p1, p3 is against
if (p1p2 == p1p4 && p2p3 == p3p4 && p1p2 == p2p3) {
return abs(p1p2 * sqrt(2) - p1p3) <= epsilon;
}
// p1,p4 is against
if (p1p2 == p1p3 && p2p4 == p3p4 && p1p2 == p2p4) {
return abs(p1p2 * sqrt(2) - p1p4) <= epsilon;
}
return false;
}
};
边栏推荐
- IPv6 Foundation
- Similarities and differences of QWidget, qdialog and qmainwindow
- [image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
- Niuke net brush questions
- Qt 之自定义界面(实现无边框、可移动)
- 【无标题】
- 【一起学Rust | 基础篇】Rust基础——变量和数据类型
- Proficient in audio and video development can really do whatever you want
- 【Unity3D】角色控制器(CharacterController)
- [image processing] image skeleton extraction based on central axis transformation with matlab code
猜你喜欢

Peking University open classes are coming! Welcome to the "AI for science" class

2022年企业直播行业发展洞察

How to use grep to find pattern matching across multiple lines
【一起学Rust | 基础篇】Rust基础——变量和数据类型

mapbox 地图 生成矢量数据圆

Learning with Recoverable Forgetting readings

QML(二):设置自定义窗体

Building and sharing the root of the digital world: Alibaba Cloud builds a comprehensive cloud-native open source ecosystem

The interviewer training courseware (very practical in-house training courseware)

报表查询字段集sql摘记
随机推荐
2.3插入排序
Package delivery (greedy)
2022 latest WiFi master applet independent version 3.0.8
黑马四小时入门学习记录-2|本地应用
【一起学Rust | 基础篇】Rust基础——变量和数据类型
通过递归的方式实现树形结构
PaddleLite 编译以及代码跑通复盘
Insights into the development of the enterprise live broadcast industry in 2022
MarkDown高阶语法手册
【一起学Rust | 基础篇】rust函数与流程控制详解
测试环境要多少,从现实需求说起
INVALID_ARGUMENT : Invalid rank for input: modelInput Got: 3 Expected: 4 Please fix either the input
PL/SQL 集合
SkiaSharp 之 WPF 自绘 弹动小球(案例版)
Basic. Blocking
精通音视频开发是真的可以为所欲为
Out-of-the-box problem-solving thinking, putting a "rearview mirror" on the unconscious life
Golang realizes file upload and download
MyCat中间件高可用、读写分离、分片、主从切换、ER分片
Std:: vector copy, append, nested access