hihocoder 1040 矩形判断解题报告
2016-05-14 21:44
281 查看
用来热身的一道题目,根据题意输入8个点表示4条线,可以利用4个向量来表示这四条线,判断是否组成矩形只需拿出任一条向量判断其余3条向量是否有两条垂直向量,两条平行向量。如果有,则构成矩形,没有则输出"NO"
代码如下。
代码如下。
#include <iostream> #include <algorithm> #include <cstdio> using namespace std; const int num = 4; struct Data { int x,y; }; struct line { Data one,two; line(int a = 0,int b = 0,int c = 0,int d = 0) { one.x = a;one.y = b; two.x = c;two.y = d; } }T[num]; void input() { int a,b,c,d; for(int i = 0; i < 4; ++i) { scanf("%d%d%d%d",&a,&b,&c,&d); T[i] = *new struct line(a,b,c,d); } } bool check() { int p = 0,cu = 0; int a = T[0].one.x,b = T[0].one.y,c = T[0].two.x,d = T[0].two.y; int a2,b2,c2,d2; for(int i = 1; i < 4;++i) { a2 = T[i].one.x; b2 = T[i].one.y; c2 = T[i].two.x; d2 = T[i].two.y; int x1 = c - a; int y1 = d - b; int x2 = c2 - a2; int y2 = d2 - b2; if(x1 * x2 + y1 * y2 == 0) cu++; if(x2 * y1 - y2 * x1 == 0) p++; } if(cu == 2 && p == 1) return true; else return false; } int main() { int n;cin>>n; while(n--) { input(); if(check()) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- TableView的优化
- BestCoder Round #83 zxa and wifi(一个奇怪的DP题)
- 今天讲一讲简单的图片叠加式的动画创建,帧动画
- SDUT 3297 奇妙的23点
- dom4j 解析xml
- Sticks POJ 1011 搜索题
- 软件众包 业余主义的复兴
- BestCoder Round #83 Problem1001 zxa and set
- c/s模式 (C#)下Ftp的多文件上传及其上传进度
- java多线程系列7-停止线程
- math.floor实现四舍五入
- Java NIO系列教程(三) Buffer
- breakdebug
- JavaSE_String 截取字符串 String.substring
- 水题 kruskal算法求最小生成树
- poj-2312-Battle City
- OSX安装homebrew以及正确安装PIL(包括jpeg)的方法
- AndroidStudio开发Gradle学习
- 72. Edit Distance 动态规划dp
- Android中Binder进程间通信库