当前位置: 首页 > wzjs >正文

网站开发地图做百科专用参考链接的网站

网站开发地图,做百科专用参考链接的网站,湖南长沙又检出1例阳性,做美食网站的图片给定平面上四个点的坐标,判断这四个点是否形成正方形。 要检查正方形,我们需要检查以下内容: a) 由点形成的所有四条边都相同。 b) 任何两条边之间的角度都是 90 度。(此条件是必需的,因为菱形 也有相同的边&am…

 给定平面上四个点的坐标,判断这四个点是否形成正方形。 

要检查正方形,我们需要检查以下内容:
        a) 由点形成的所有四条边都相同。
        b) 任何两条边之间的角度都是 90 度。(此条件是必需的,因为菱形 也有相同的边)
        c) 检查两条对角线的距离是否相同.

例子:

输入: p1 = { 20, 10 }, p2 = { 10, 20 }, p3 = { 20, 20 }, p4 = { 10, 10 }
输出: 是
解释: 

输入: p1 = { 20, 20 }, p2 = { 10, 20 }, p3 = { 20, 20 }, p4 = { 10, 10 }
输出: 否 

        方法:思路是选取任意一点并计算其与其余点的距离。设选取的点为“p”。要形成正方形,两个点与“p”的距离必须相同,设该距离为 d。与一个点的距离必须不同于 d,并且必须等于 d 的 2 倍。设距离不同的这个点为“q”。 

        上述条件还不够好,因为距离不同的点可能在另一侧。我们还需要检查 q 是否与其他 2 个点的距离相同,并且该距离与 d 相同。

以下是上述想法的实现:

// A C# program to check if four given points form a square or not.
using System;
 
class GFG
{
 
// Structure of a point in 2D space
class Point 
{
    public int x, y;
 
    public Point(int x, int y) 
    {
        this.x = x;
        this.y = y;
    }
     
};
 
// A utility function to find square of distance
// from point 'p' to point 'q'
static int distSq(Point p, Point q)
{
    return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
 
// This function returns true if (p1, p2, p3, p4) form a
// square, otherwise false
static bool isSquare(Point p1, Point p2, Point p3, Point p4)
{
    int d2 = distSq(p1, p2); // from p1 to p2
    int d3 = distSq(p1, p3); // from p1 to p3
    int d4 = distSq(p1, p4); // from p1 to p4
 
    if (d2 == 0 || d3 == 0 || d4 == 0)    
        return false;
 
    // If lengths if (p1, p2) and (p1, p3) are same, then
    // following conditions must met to form a square.
    // 1) Square of length of (p1, p4) is same as twice
    // the square of (p1, p2)
    // 2) Square of length of (p2, p3) is same
    // as twice the square of (p2, p4)
    if (d2 == d3 && 2 * d2 == d4
        && 2 * distSq(p2, p4) == distSq(p2, p3))
    {
        return true;
    }
 
    // The below two cases are similar to above case
    if (d3 == d4 && 2 * d3 == d2
        && 2 * distSq(p3, p2) == distSq(p3, p4)) 
    {
        return true;
    }
    if (d2 == d4 && 2 * d2 == d3
        && 2 * distSq(p2, p3) == distSq(p2, p4))
    {
        return true;
    }
    return false;
}
 
// Driver code
public static void Main(String[] args)
{
    Point p1 = new Point(20, 10), p2 = new Point(10, 20),
        p3 = new Point(20, 20), p4 = new Point(10, 10);
    Console.WriteLine(isSquare(p1, p2, p3, p4) == true ? "Yes" : "No");
}
}
 
// This code is contributed by 29AjayKumar 

输出:

时间复杂度: O(1),所有操作都在 O(1) 常数时间内执行。

辅助空间: O(1),不需要额外空间

扩展: 检查四个线段是否形成一个矩形
JavaScript:https://blog.csdn.net/hefeng_aspnet/article/details/145686594
C#:https://blog.csdn.net/hefeng_aspnet/article/details/145686569
Python:https://blog.csdn.net/hefeng_aspnet/article/details/145686543
Java:https://blog.csdn.net/hefeng_aspnet/article/details/145686509
C++:https://blog.csdn.net/hefeng_aspnet/article/details/145686317 

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。 


文章转载自:

http://AVGxheam.tytLy.cn
http://XYmzxcQ8.tytLy.cn
http://K1SqVKys.tytLy.cn
http://78DxJXHi.tytLy.cn
http://gyXP6UlN.tytLy.cn
http://Zua3xkwx.tytLy.cn
http://1qQziz9n.tytLy.cn
http://xBoEmzr5.tytLy.cn
http://9yUlNeVj.tytLy.cn
http://d9bLFzWB.tytLy.cn
http://0WPvkpXS.tytLy.cn
http://Wrst5xuK.tytLy.cn
http://3fGBRcNx.tytLy.cn
http://wTlmDKFD.tytLy.cn
http://yV5yogN4.tytLy.cn
http://mXGXwn3s.tytLy.cn
http://gNLJl3kP.tytLy.cn
http://aYpqYOgL.tytLy.cn
http://L9PFifSs.tytLy.cn
http://SgwuQDtS.tytLy.cn
http://6j7DCpU5.tytLy.cn
http://hQSlOASI.tytLy.cn
http://sLI6xlFm.tytLy.cn
http://UB2Oqh15.tytLy.cn
http://sHzvSt25.tytLy.cn
http://mJNvB9GL.tytLy.cn
http://sbkBVj6k.tytLy.cn
http://zscHjWLt.tytLy.cn
http://U8o5Y8tD.tytLy.cn
http://oWIGiO0W.tytLy.cn
http://www.dtcms.com/wzjs/721594.html

相关文章:

  • 网站改版需求网络网站如何推广
  • 网站关键词选取方法杭州开发网站
  • 厦门网站制作策划免费的网站程序
  • 五河网站建设哪家好软文模板app
  • 哪个网站做相片书好做家装的网站有什么区别
  • 网站建设应该注意的问题wordpress板块大小
  • 建设网站的效益分析房地产 东莞网站建设
  • 网站建设费可以一次性冲费用吗邯郸h5开发
  • 做网站公司教程php管理系统
  • 创办一个网站需要多少资金网站空间域名是什么
  • 网站设计技术有哪些?通辽市 做网站
  • 小说网站建设多少钱自己网站首页如何设置
  • 网站更新中网站安全狗服务名
  • 苏州住房和城乡建设局网站首页是否有可能一个人完成网站开发
  • 下载app软件安装手机上织梦网站建设后优化步骤
  • 网站开发需要什么资质济南教育平台网站建设
  • 一个外贸网站要多大的空间比较好别人品牌的域名做网站吗
  • 泰安建网站wordpress用户注册设置密码
  • 网站建设合同服务事项wordpress主题安装和更改
  • 顺德品牌网站建设价格自建视频网站
  • 网站做反向代理对百度收录有影响吗网站wordpress是什么
  • 网站开发属于什么系统机电建设工程施工网站
  • 网站建设开发方式包括哪些小程序开发者工具下载
  • 网站其它方面seo情况如何做免费的网站
  • 浙江建设报名网站提供手机网站建设
  • dede 网站地图 插件广州番禺区号
  • 网站开发提供的服务网站建设哪个平台最好
  • 网站无后台添加后台wordpress进后台慢
  • 电子商务网站开发的目的是什么厦门网络科技有限公司
  • 第一页网站SEO高端品牌鞋子