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 ...
随机推荐
- ACM题目————二叉树的遍历
一.二叉树的后序遍历: 题目描述 给定一颗二叉树,要求输出二叉树的深度以及后序遍历二叉树得到的序列.本题假设二叉树的结点数不超过1000 输入 输 入数据分为多组,第一行是测试数据的组数n,下面的n行 ...
- java 1G大文件复制
对比几种复制方法 复制的文件是980m的txt文件 1. FileChannel 方法 代码: public static void mappedBuffer() throws IOExceptio ...
- c#之线程池
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- Parencodings 分类: POJ 2015-06-28 22:00 7人阅读 评论(0) 收藏
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22757 Accepted: 13337 De ...
- GOICE项目初探
GOICE项目初探 在图像拼接方面,市面上能够找到的软件中,要数MS的ICE效果.鲁棒性最好,而且界面也很美观.应该说有很多值得学习的地方,虽然这个项目不开源,但是利用现有的资料,也可 ...
- 浅谈算法和数据结构: 七 二叉查找树 八 平衡查找树之2-3树 九 平衡查找树之红黑树 十 平衡查找树之B树
http://www.cnblogs.com/yangecnu/p/Introduce-Binary-Search-Tree.html 前文介绍了符号表的两种实现,无序链表和有序数组,无序链表在插入的 ...
- python学习笔记-day4笔记 常用内置函数与装饰器
1.常用的python函数 abs 求绝对值 all 判断迭代器中所有的数据是否为真或者可迭代数据为空,返回真,否则返回假 any ...
- Entity Framework 第六篇 分页查询
目前分页支持单表 , ) where TEntity : class { ) * size; var _reset = Get(filter, orderBy); total = _reset.Cou ...
- reactjs入门到实战(六)---- ReactJS组件API详解
全局的api 1.React.createClass 创建一个组件类,并作出定义.组件实现了 render() 方法,该方法返回一个子级.该子级可能包含很深的子级结构.组件与标准原型类的不同之处在于, ...
- JS常用的腳本庫--包括在線編輯器
原文链接 一.基本库 1.jQuery a.简介 JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, F ...