hihoCoder #1040 (判断是否为矩形)
题目大意:给四条线段,问能否构成一个矩形?
题目分析:先判断能否构成四边形,然后选一条边,看另外三条边中是否为一条与他平行,两条垂直。
代码如下:
# 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 (判断是否为矩形)的更多相关文章
- Rectangle and Square(判断正方形、矩形)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D 改了N多次之后终于A了,一直在改判断正方形和矩形那,判断 ...
- 判断圆和矩形是否相交C - Rectangle and Circle
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...
- HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1221 Rectangle and Circle Time Limit: 2000/1000 MS (J ...
- poj 1410 Intersection (判断线段与矩形相交 判线段相交)
题目链接 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12040 Accepted: 312 ...
- Intersection--poj1410(判断线段与矩形的关系)
http://poj.org/problem?id=1410 题目大意:给你一个线段和矩形的对角两点 如果相交就输出'T' 不想交就是'F' 注意: 1,给的矩形有可能不是左上 右下 所以要先判 ...
- 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 ...
- poj1410(判断线段和矩形是否相交)
题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...
- hihoCoder 1040 矩形判断(计算几何)
http://hihocoder.com/problemset/problem/1040 首先判断四条线段是否相交,给出八个点,如果有一些点重合,并且不同坐标的点只有4个的话,表示可以构成四边形. 然 ...
- hihocoder #1040 矩形判断(计算几何问题 给8个点的坐标,能否成为一个矩形 【模板思路】)
#1040 : 矩形判断 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 给出平面上4条线段,判断这4条线段是否恰好围成一个面积大于0的矩形. 输入 输入第一行是一个整数T ...
随机推荐
- BPM的四大主要类型
随着网络的发展,移动BPM.社交BPM.云端BPM将顺应市场需求,成为BPM发展的新趋势,最终成为企业即时管控有效工具.BPM将不断促进制造业信息化的转型与发展.所以很少人会否认业务流程管理(BPM) ...
- 计算文字的高度和宽度--以微博会话界面中用户名(userName)为例
所用方法 // NOTE: All of the following methods will default to drawing on a baseline, limiting drawing t ...
- SharePoint 2013 开发——开发并部署Provider-hosted APP
博客地址:http://blog.csdn.net/FoxDave 本篇我们用Visual Studio创建并部署一个SharePoint Provider-hosted应用程序. 打开Visua ...
- C#判断IP地址是否合法函数-使用正则表达式-2个 (转)
public bool IsCorrenctIP(string ip){ string pattrn=@"(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2} ...
- 匹配IP地址的正则表达式 (转)
正则表达式 ^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[ ...
- (转)Android学习笔记---SQLite介绍,以及使用Sqlite,进行数据库的创建,完成数据添删改查的理解
原文:http://blog.csdn.net/lidew521/article/details/8655229 1.SQLite介绍:最大特点是,无数据类型;除了可以使用文件或SharedPrefe ...
- Python 类的一些BIF
issubclass issubclass(cls, class_or_tuple, /) Return whether 'cls' is a derived from another class o ...
- SSO单点登录
登录持久化机制:Cookies&&Session Cookie:是将信息存储到客户端,所有的信息不安全,都会对信息进行加密,cookies中会存储当前会话的唯一标识,即SessionI ...
- iOS教程
iOS绘图教程: http://www.cocoachina.com/industry/20140115/7703.html iOS基础教程:--包含脚本 swift http://bbs.zxope ...
- 判断字符串中是否有SQL攻击代码
判断一个输入框中是否有SQL攻击代码 public const string SQLSTR2 = @"exec|cast|convert|set|insert|select|delete|u ...