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 ...
随机推荐
- 从协议VersionedProtocol开始1
Phase 0: Make a plan You must first decide what steps you're going to have in your process. It sound ...
- Great writers inspire
William Shakespeare Beowulf (Anglo-Saxon) Jonathan Swift Stephen Duck William Blake George Elliot Ka ...
- [转]source inslght使用指导
作为一个开放源代码的操作系统,Linux附带的源代码库使得广大爱好者有了一个广泛学习.深入钻研的机会,特别是Linux内核的组织极为复杂,同时,又不能像windows平台的程序一样,可以使用集成开发环 ...
- C# 使用命令行编译单个CS文件
编译单个CS文件. 1.编译 File.cs 以产生 File.exe: csc File.cs 2.编译 File.cs 以产生 File.dll: ...
- struts2中form提交到action中的中文参数乱码问题解决办法(包括取中文路径)
我的前台页是这样的: <body> <form action="test.action" method="post"> ...
- 关于python3 OpenCV的安装和配置
开发环境,win7 32bit, Anaconda3.之前尝试pip安装,但是总是不成功.后来,交流群里面废帝大神让我用conda安装,之后按照conda install --channel http ...
- simple grammer
<?phpecho strlen("Hello world!"); // outputs 12?> <?phpecho str_word_count(" ...
- HTTP请求错误大全
HTTP 400 - 请求无效HTTP 401.1 - 未授权:登录失败 HTTP 401.2 - 未授权:服务器配置问题导致登录失败 HTTP 401.3 - ACL 禁止访问资源 HTTP 401 ...
- 程序员是怎么炼成的---OC题集--练习答案与题目(3)
1.init 2.initWithBytes:length:encoding: 3.initWithCharacters:length: 4.initWithCString:encoding: 5.i ...
- HDU5534--Partial Tree (完全背包)
点击打开链接 思路:总度数为2n-2,由于每个节点都至少要有1个度,所以可以看做把剩余n-2个点放入n个节点的背包问题.dp[i]表示放入i个度后的最大值 #include<cstdio> ...