uva 11800 Determine the Shape
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的更多相关文章
- UVA 11800 - Determine the Shape 几何
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11800 Determine the Shape --凸包第一题
题意: 给四个点,判断四边形的形状.可能是正方形,矩形,菱形,平行四边形,梯形或普通四边形. 解法: 开始还在纠结怎么将四个点按序排好,如果直接处理的话,有点麻烦,原来凸包就可搞,直接求个凸包,然后点 ...
- 简单几何(四边形形状) UVA 11800 Determine the Shape
题目传送门 题意:给了四个点,判断能构成什么图形,有优先规则 分析:正方形和矩形按照点积为0和长度判断,菱形和平行四边形按向量相等和长度判断,梯形按照叉积为0判平行.因为四个点是任意给出的,首先要进行 ...
- ArcGIS Engine开发的ArcGIS 版本管理的功能
原文:ArcGIS Engine开发的ArcGIS 版本管理的功能 转自:http://blog.csdn.net/linghe301/article/details/7965901 这是以前的Arc ...
- [Bayes] Understanding Bayes: Updating priors via the likelihood
From: https://alexanderetz.com/2015/07/25/understanding-bayes-updating-priors-via-the-likelihood/ Re ...
- Xtreme9.0 - Mr. Pippo's Pizza 数学
Mr. Pippo's Pizza 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/mr-pipp ...
- Video processing systems and methods
BACKGROUND The present invention relates to video processing systems. Advances in imaging technology ...
- 插入2D点,在WPF中使用Bezier曲线
原文Interpolate 2D points, usign Bezier curves in WPF Interpolate 2D points, usign Bezier curves in WP ...
- Unity Glossary
https://docs.unity3d.com/2018.4/Documentation/Manual/Glossary.html 2D terms 2D Physics terms AI term ...
随机推荐
- css写法优化
写css关于id,class等的命名,文件的结构,共同模块的提取,代码的复用性,可读性,扩展性,维护性都要考虑,不然后期可以会需要花大力气去进行维护修改.考虑写出足够科学的css,需要考虑下面几个方面 ...
- 进程外session
进程外session A SqlServer 1.管理员身份运行cmd 2.更换目录 cd c:\Windows\Microsoft.NET\Framework\v4.0.30319> 3. ...
- JAVA基础知识之网络编程——-使用MutilcastSocket实现多点广播
IP多点广播原理 设置一组特殊网络地址作为多点广播地址,每一个多点广播地址都被看作一个组,当客户需要发送和接受信息时,加入到该组即可. IP协议为多点广播提供了一批特殊的IP地址,范围是224.0.0 ...
- lhgdialog在打开的窗口里点击按钮关闭当前窗口
lhgdialog在打开的窗口里点击按钮关闭当前窗口 var api = frameElement.api, W = api.opener; api.close();
- js判断手机连接网络类型
<!DOCTYPE HTML><html xmlns="http://www.w3.org/1999/xhtml" lang="en"> ...
- 2016年10月27日 星期四 --出埃及记 Exodus 19:12
2016年10月27日 星期四 --出埃及记 Exodus 19:12 Put limits for the people around the mountain and tell them, `Be ...
- [转]Linq中GroupBy方法的使用总结
Demo模型类: public class StudentScore { public int ID { set; get; } public string Name { set; get; } pu ...
- Linux源代码分析工具链
前言 看源代码是一个程序员必须经历的事情,也是可以提升能力的一个捷径.个人认为: 要完全掌握一个软件的方法只有阅读源码. 在Windows下有sourceinsight这个源码阅读软件(虽然我没用过, ...
- ASP.NET文件的上传下载提交分页
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" Auto ...
- GMT时间转换
/// <summary> /// GMT时间转成本地时间 /// </summary> /// <param name="gmt">字符串形式 ...