vjudge上题目链接:Determine the Shape

  第二道独自 A 出的计算几何水题,题意就是给你四个点,让你判断它是哪种四边形:正方形、矩形、菱形、平行四边形、梯形 or 普通四边形。

  按照各个四边形的特征层层判断就行,只是这题四个点的相对位置不确定(点与点之间是相邻还是相对并不确定),所以需要枚举各种情况,幸好 4 个点一共只有 3 种不同的情况:abcd、abdc、acbd 画个图就能一目了然,接下来就是编码了,无奈因为一些细节问题我还是调试了还一会 o(╯□╰)o

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; struct Vector {
double x,y;
Vector(double x = , double y = ): x(x), y(y) {}
void readint() {
int x,y;
scanf("%d %d",&x,&y);
this->x = x;
this->y = y;
}
Vector operator + (const Vector &b) const {
return Vector(x + b.x, y + b.y);
}
Vector operator - (const Vector &b) const {
return Vector(x - b.x, y - b.y);
}
Vector operator * (double p) const {
return Vector(x * p, y * p);
}
Vector operator / (double p) const {
return Vector(x / p, y / p);
}
}; typedef Vector point;
typedef const point& cpoint;
typedef const Vector& cvector; Vector operator * (double p, const Vector &a) {
return a * p;
} double dot(cvector a, cvector b) {
return a.x * b.x + a.y * b.y;
} double length(cvector a) {
return sqrt(dot(a,a));
} double cross(cvector a, cvector b) {
return a.x * b.y - a.y *b.x;
} const double eps = 1e-;
int dcmp(double x) {
return fabs(x) < eps ? : (x < ? - : );
} bool operator == (cpoint a, cpoint b) {
return dcmp(a.x - b.x) == && dcmp(a.y - b.y) == ;
} const char s[][] = {"Ordinary Quadrilateral", "Trapezium", "Parallelogram",
"Rhombus", "Rectangle", "Square" }; int judge(cpoint a, cpoint b, cpoint c, cpoint d) {
if(dcmp(cross(a - b, c - d)) == ) {
if(dcmp(cross(b - c, a - d)) == ) {
if(dcmp(length(b - a) - length(d - a)) == ) {
if(dcmp(dot(b - a, d - a)) == ) return ;
else return ;
}
else if(dcmp(dot(b - a, d - a)) == ) return ;
else return ;
}
else return ;
}
else if(dcmp(cross(b - c, a - d)) == ) return ;
else return ;
} int main() {
int t,Case = ;
point a,b,c,d;
scanf("%d",&t);
while(t--) {
a.readint();
b.readint();
c.readint();
d.readint();
printf("Case %d: ",++Case);
int ans = ;
ans = max(ans, judge(a,b,c,d));
ans = max(ans, judge(a,b,d,c));
ans = max(ans, judge(a,c,b,d));
printf("%s\n",s[ans]);
}
return ;
}

  计算几何,还是很有趣的。。。

uva 11800 Determine the Shape的更多相关文章

  1. UVA 11800 - Determine the Shape 几何

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. UVA 11800 Determine the Shape --凸包第一题

    题意: 给四个点,判断四边形的形状.可能是正方形,矩形,菱形,平行四边形,梯形或普通四边形. 解法: 开始还在纠结怎么将四个点按序排好,如果直接处理的话,有点麻烦,原来凸包就可搞,直接求个凸包,然后点 ...

  3. 简单几何(四边形形状) UVA 11800 Determine the Shape

    题目传送门 题意:给了四个点,判断能构成什么图形,有优先规则 分析:正方形和矩形按照点积为0和长度判断,菱形和平行四边形按向量相等和长度判断,梯形按照叉积为0判平行.因为四个点是任意给出的,首先要进行 ...

  4. ArcGIS Engine开发的ArcGIS 版本管理的功能

    原文:ArcGIS Engine开发的ArcGIS 版本管理的功能 转自:http://blog.csdn.net/linghe301/article/details/7965901 这是以前的Arc ...

  5. [Bayes] Understanding Bayes: Updating priors via the likelihood

    From: https://alexanderetz.com/2015/07/25/understanding-bayes-updating-priors-via-the-likelihood/ Re ...

  6. Xtreme9.0 - Mr. Pippo's Pizza 数学

    Mr. Pippo's Pizza 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/mr-pipp ...

  7. Video processing systems and methods

    BACKGROUND The present invention relates to video processing systems. Advances in imaging technology ...

  8. 插入2D点,在WPF中使用Bezier曲线

    原文Interpolate 2D points, usign Bezier curves in WPF Interpolate 2D points, usign Bezier curves in WP ...

  9. Unity Glossary

    https://docs.unity3d.com/2018.4/Documentation/Manual/Glossary.html 2D terms 2D Physics terms AI term ...

随机推荐

  1. 类型解释器——C专家编程读书笔记

    对于声明,应该按下面的步骤来进行解释: 1) 声明从它的名字开始读取,然后按照优先级顺序依次读取 2) 优先级顺序 a) 括号括起来的部分 b) 后缀操作符,()表示函数,[]表示数组 c) 前缀操作 ...

  2. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  3. Shuffle'm Up 分类: 函数 POJ 查找 2015-08-09 17:01 6人阅读 评论(0) 收藏

    Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7529 Accepted: 3466 Descript ...

  4. HDU(1175),连连看,BFS

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1175 越学越不会,BFS还是很高级的. 连连看 Time Limit: 20000/100 ...

  5. tensor

    初始化 z = torch.Tensor(,,,,) --可以创建多维数组.里面是随机的数. s = torch.Tensor(,):fill() --用1填充 t = torch.rand(,) m ...

  6. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  7. c++中两种常量方法的比较

    [c++]在C++中定义常量的两种方法的比较   常量是定以后,在程序运行中不能被改变的标识符.C++中定义常量可以用#define .const 这两种方法.例如: #define PRICE 10 ...

  8. C#数组的排序(正序逆序)

    C#数组的排序(正序逆序) 这种排序 超级简单的 ! using System; using System.Collections.Generic; using System.Linq; using ...

  9. redis pool

    Redis Pool--Java 配置文件 #redis conf ADDR=127.0.0.1 PORT= AUTH= #session timeout TIMEOUT= MAX_ACTIVE= M ...

  10. 窗口移动--基类(BaseForm)

    #region 窗口移动 private bool _isLeftButtonDown = false; public const int HTCAPTION = 0x0002; protected ...