hihocoder#1040判断矩形
2015-07-26 21:53
495 查看
//先判断是否重合存在4个点然后判断是否是平行或者垂直的
#include <iostream> #include <vector> #include <set> #include<stdio.h> using namespace std; struct xpoint { int x1,y1; bool operator<(const xpoint&ls)const { if (x1==ls.x1) return y1<ls.y1; return x1<ls.x1; } bool operator==(const xpoint&ls)const { return x1==ls.x1&&y1==ls.y1; } }; struct Line { int x1,y1; int x2,y2; }; static int cnt = 0; //判断垂直 static int dot(Line&l1,Line&l2) { int tmpx1 = l1.x2 - l1.x1; int tmpy1 = l1.y2 - l1.y1; int tmpx2 = l2.x2 - l2.x1; int tmpy2 = l2.y2 - l2.y1; return tmpx1*tmpx2+tmpy1*tmpy2; } //判断平行 static int xoper(Line&l1,Line&l2) { int tmpx1 = l1.x2 - l1.x1; int tmpy1 = l1.y2 - l1.y1; int tmpx2 = l2.x2 - l2.x1; int tmpy2 = l2.y2 - l2.y1; return tmpx1*tmpy2 - tmpx2*tmpy1; } static bool isCube(vector<Line>&lines) { //判断是否平行或者垂直 for(int i=0;i<lines.size();++i) { for (int j=i+1;j<lines.size();++j) if (xoper(lines[i],lines[j])==0|| dot(lines[i],lines[j])==0) continue; else return false; } return true; } int main() { int T; scanf("%d",&T); while(T--) { vector<Line>lins; int x1,x2,y1,y2; Line tmp; set<xpoint>vset; xpoint pttmp; for (int i=0;i<4;++i) { scanf("%d %d %d %d",&x1,&y1,&x2,&y2); tmp.x1 = x1;tmp.x2 = x2; tmp.y1 = y1;tmp.y2 = y2; pttmp.x1 = x1;pttmp.y1 = y1; vset.insert(pttmp); pttmp.x1 = x2;pttmp.y1 = y2; vset.insert(pttmp); lins.push_back(tmp); } if (vset.size()==4) { if (isCube(lins)) printf("YES\n"); else printf("NO\n"); } else { printf("NO\n"); } } return 0; }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- 使用Lua来扩展C++程序的方法
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- C++ Custom Control控件向父窗体发送对应的消息
- C++中拷贝构造函数的应用详解