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. SlickGrid example 7:鼠标事件

    响应鼠标事件,可以左键快捷选择切换选项,可右键弹出菜单栏.   代码: <!DOCTYPE HTML> <html> <head> <meta http-eq ...

  2. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  3. 验证码识别--type5

    验证码识别--type5 每一种验证码都是由人设计出来.在设计过程中,可能由于多个方面的原因,造成了这样或那样的可以被利用的漏洞.验证码识别,首先需要解决的问题就是发现这些漏洞--然后利用漏洞解决问题 ...

  4. Unity安卓上播放视频的问题,暂时无解记录一下

    设备联想A7600m,好像是联发科的cpu 先用网上流传很广的这个Unity自带接口试验一下: Handheld.PlayFullScreenMovie(Path.Combine(Applicatio ...

  5. JAVA基础知识之List集合

    List接口和ListIterator接口介绍 List集合新增方法 List集合判断元素重复的标准 ListIterator List.ArrayList和List.Vector 固定长度的List ...

  6. 如何快捷输入函数上方的注释代码(Summary)

    写完类或函数(注意必须写完,不然出现的信息会不完整)后,在其上方空行输入/**,然后回车,就可以为其添加Summary.    

  7. 新蒂下午茶体基本版SentyTEA-Basic

    一.目前的最新版新蒂下午茶体包含了7600+常用汉字,每个字都是手写而成,是一套充满手写感的中文字体,轻松.惬意,如同慢饮一杯下午茶.SentyTEA-Basic.ttf  这个一个新蒂下午茶体基本版 ...

  8. easyUI的window包含一个iframe,在iframe中如何关闭window?

    easyUI的window包含一个iframe,在iframe中如何关闭window? parent.$('#win').window('close');

  9. CodeForces 670D2 Magic Powder 二分

    D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...

  10. C#实现随机抽奖和冒泡排序

    随机抽奖程序 string[] s = new string[] { "A", "B", "C", "D", " ...