题目大意:给四条线段,问能否构成一个矩形?

题目分析:先判断能否构成四边形,然后选一条边,看另外三条边中是否为一条与他平行,两条垂直。

代码如下:

# include<iostream>
# include<cstdio>
# include<cmath>
# include<set>
# include<cstring>
# include<algorithm>
using namespace std;
# define LL long long const double inf=1e20;
const double eps=1e-20; struct Edge
{
LL x,y;
double k;
};
Edge e[4];
set<LL>s; double getK(int i)
{
if(e[i].x==0) return inf;
return (double)e[i].y/(double)e[i].x;
} bool ok(int i,int j)
{
return e[i].x*e[j].x+e[i].y*e[j].y==0ll;
} bool judge()
{
if(s.size()!=4) return false;
int cnt1=0,cnt2=0;
for(int i=1;i<4;++i){
if(ok(0,i)) ++cnt1;
if(e[0].k==e[i].k) ++cnt2;
}
return cnt1==2&&cnt2==1;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
LL a,b,c,d;
s.clear();
for(int i=0;i<4;++i){
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
s.insert(a*100000ll+b);
s.insert(c*100000ll+d);
e[i].x=c-a;
e[i].y=d-b;
e[i].k=getK(i);
}
if(judge()) printf("YES\n");
else printf("NO\n");
}
return 0;
}

  

hihoCoder #1040 (判断是否为矩形)的更多相关文章

  1. Rectangle and Square(判断正方形、矩形)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D 改了N多次之后终于A了,一直在改判断正方形和矩形那,判断 ...

  2. 判断圆和矩形是否相交C - Rectangle and Circle

    Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...

  3. HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1221 Rectangle and Circle Time Limit: 2000/1000 MS (J ...

  4. poj 1410 Intersection (判断线段与矩形相交 判线段相交)

    题目链接 Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12040   Accepted: 312 ...

  5. Intersection--poj1410(判断线段与矩形的关系)

    http://poj.org/problem?id=1410 题目大意:给你一个线段和矩形的对角两点  如果相交就输出'T'  不想交就是'F' 注意: 1,给的矩形有可能不是左上 右下  所以要先判 ...

  6. Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

    C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...

  7. poj1410(判断线段和矩形是否相交)

    题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...

  8. hihoCoder 1040 矩形判断(计算几何)

    http://hihocoder.com/problemset/problem/1040 首先判断四条线段是否相交,给出八个点,如果有一些点重合,并且不同坐标的点只有4个的话,表示可以构成四边形. 然 ...

  9. hihocoder #1040 矩形判断(计算几何问题 给8个点的坐标,能否成为一个矩形 【模板思路】)

    #1040 : 矩形判断 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 给出平面上4条线段,判断这4条线段是否恰好围成一个面积大于0的矩形. 输入 输入第一行是一个整数T ...

随机推荐

  1. Program A-归并排序

    Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...

  2. @Param注解在mybatis中的使用以及传入参数的几种方式(转)

    第一种: Dao层的方法 <span style="font-size:12px;">Public User selectUser(String name,String ...

  3. git——学习笔记(三)分支管理

    一.创建.合并分支 每次提交,git都往后走一格,串成一跳时间线,head指向的是分支,分支指向提交.master是主分支,dev是另一条分支,分支就像指针一样,合并.删除分支时,修改的都是指针,工作 ...

  4. 《用格式化(fprintf和fscanf函数)的方式读写文件》

    //用格式化(fprintf和fscanf函数)的方式读写文件 [用格式化的方式向文件中写入数据]#include<stdio.h>#include<stdlib.h> int ...

  5. 深入理解SELinux

      目录(?)[+]   1. 简介 SELinux带给Linux的主要价值是:提供了一个灵活的,可配置的MAC机制. Security-Enhanced Linux (SELinux)由以下两部分组 ...

  6. Security Checklist (路由器安全checklist)

    Security Checklist Website by     Michael Horowitz  Home | Introduction | Router Bugs | Security Che ...

  7. Matlab单一变量曲线拟合-cftool

    2.启动曲线拟合工具箱>cftool 3.进入曲线拟合工具箱界面“Curve Fitting tool”(1)点击“Data”按钮,弹出“Data”窗口:(2)利用X data和Y data的下 ...

  8. bistu新生-1005

    #include "stdio.h"#include "string.h"int main(){ char ku[]={'0','1','2','3','4', ...

  9. linux下的文件权限管理

    权限管理有两个层面 第一层区分用户:文件属主(u), 组用户(g), 其它(o) 第二层区分权限:读(r),写(w),可执行(x) 这两个层次构成文件权限管理的二维结构 u         g     ...

  10. Office word excel电子表格在线编辑的实现方法

    Office xp之后的版本支持通过webdav协议(http的扩展)直接编辑服务器上的文件. IIS(6.0)支持webdav,这在IIS管理器的web服务扩展中可以看到.利用IIS作为webdav ...