UVA 11800 - Determine the Shape 几何
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2900
题目大意:
给定平面上的4个点,没有3点共线,你的任务是判断着4个点能组成什么样的四边形。(正方形,矩形,菱形,平行四边形,菱形,梯形,普通四边形)
思路:
从后面开始判断,梯形一组平行边即可。
平行四边形要两组,而菱形对角线垂直,矩形有一个角为直角,正方形既是矩形又是菱形。
至于判断平行和垂直,用叉乘和点乘即可。
要注意的是,不一定是按照边a,b,c,d这样的顺序,看图就知道了
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=300+10; struct Point
{
double x, y;
Point(double x=0, double y=0):x(x),y(y) { } };
typedef Point Vector;
Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (const Vector& A, double p) { return Vector(A.x*p, A.y*p); }
double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; }
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }
Point a,b,c,d;
void print(int ans)
{
switch (ans)
{
case 0:puts("Ordinary Quadrilateral");break;
case 1:puts("Trapezium");break;
case 2:puts("Parallelogram");break;
case 3:puts("Rhombus");break;
case 4:puts("Rectangle");break;
case 5:puts("Square");break;
}
}
int solve(const Point &a,const Point &b,const Point &c,const Point &d)
{
int ans=0;
Vector ab=b-a,bc=c-b,cd=d-c,da=a-d;
if(Cross(ab,cd)==0||Cross(da,bc)==0) //梯形
ans=1;
if(Cross(ab,cd)==0&&Cross(da,bc)==0) //平行四边形
{
ans=2;
if(Dot(c-a,b-d)==0) //菱形
ans=3;
if(Dot(ab,bc)==0) //矩形
ans=4;
if(Dot(c-a,b-d)==0 && Dot(ab,bc)==0) //正方形
ans=5;
}
return ans;
}
int main()
{
int T,kase=1;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
int ans=0;
ans=solve(a,b,c,d);
ans=max(ans,solve(a,c,b,d));
ans=max(ans,solve(a,b,d,c)); printf("Case %d: ",kase++);
print(ans);
}
return 0;
}
UVA 11800 - Determine the Shape 几何的更多相关文章
- uva 11800 Determine the Shape
vjudge上题目链接:Determine the Shape 第二道独自 A 出的计算几何水题,题意就是给你四个点,让你判断它是哪种四边形:正方形.矩形.菱形.平行四边形.梯形 or 普通四边形. ...
- 简单几何(四边形形状) UVA 11800 Determine the Shape
题目传送门 题意:给了四个点,判断能构成什么图形,有优先规则 分析:正方形和矩形按照点积为0和长度判断,菱形和平行四边形按向量相等和长度判断,梯形按照叉积为0判平行.因为四个点是任意给出的,首先要进行 ...
- UVA 11800 Determine the Shape --凸包第一题
题意: 给四个点,判断四边形的形状.可能是正方形,矩形,菱形,平行四边形,梯形或普通四边形. 解法: 开始还在纠结怎么将四个点按序排好,如果直接处理的话,有点麻烦,原来凸包就可搞,直接求个凸包,然后点 ...
- UVA 11646 - Athletics Track || UVA 11817 - Tunnelling the Earth 几何
题目大意: 两题几何水题. 1.UVA 11646 - Athletics Track 如图,体育场的跑道一圈400米,其中弯道是两段半径相同的圆弧,已知矩形的长宽比例为a:b,求长和宽的具体数值. ...
- UVA 11178 Morley's Theorem(几何)
Morley's Theorem [题目链接]Morley's Theorem [题目类型]几何 &题解: 蓝书P259 简单的几何模拟,但要熟练的应用模板,还有注意模板的适用范围和传参不要传 ...
- UVA 11437 - Triangle Fun 向量几何
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 11178 Morley's Theorem (几何问题)
题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点. 析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点, 以前还得自己算,现在计算机帮你算,更方便, ...
- UVA - 10382 Watering Grass(几何)
题意:有一个矩形,n个圆.已知矩形的长宽和圆的半径,问最少需多少个圆将矩形完全覆盖. 分析: 1.首先求圆与矩形的长的交点,若无交点,则一定不能对用最少的圆覆盖矩形有贡献. 2.如果两个圆与矩形相交所 ...
- ArcGIS Engine开发的ArcGIS 版本管理的功能
原文:ArcGIS Engine开发的ArcGIS 版本管理的功能 转自:http://blog.csdn.net/linghe301/article/details/7965901 这是以前的Arc ...
随机推荐
- XTUOJ 1238 Segment Tree
Segment Tree Accepted : 3 Submit : 21Time Limit : 9000 MS Memory Limit : 65536 KB Problem Descriptio ...
- C - The C Answer (2nd Edition) - Exercise 1-4
/* Write a program to print the corresponding Celsius to Fahrenheit table. */ #include <stdio.h&g ...
- QT就是别人好心帮你做一些枯燥,并且很重复的代码编写工作,让你更好的把精力投入到你界面的逻辑和功能的实现的功能库(否则写了上万行代码了,才写出个BUG一大堆的毛坯)
好了,现在开始记录我学习QT的学习历程 . 本人也不是计算机专业出来的,自学了一点,但还是不好找工作,于是参加了培训,虽然感觉没多学到什么 编程的学习生涯就是不断的看别人的源码,然后自己参考着写写自己 ...
- Windows下快速安装CACTI流量监控
Windows下快速安装CACTI流量监控 原文 http://os.51cto.com/art/201111/300977.htm CACTI是一套PHP程序,它利用SNMPGET采集数据,使用R ...
- 一题多解(三)—— Python 字符串的拼接
1. format def event_log(name, time): print('Event: {}, happens at {}'.format(name, str(time))) 2. 使用 ...
- 2017-百度之星 初赛-B
1001 Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- ajax关于主流中的异类:应对Opera(四)
修改示例以支持Opera <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- rune 切片 go
package main import ( "fmt" ) func main() { var s = "go程序``**//;;''[p]=-\\&|@#$%^ ...
- HDU——T 1573 X问题
http://acm.hdu.edu.cn/showproblem.php?pid=1573 Time Limit: 1000/1000 MS (Java/Others) Memory Limi ...
- UVA 11346 Probability (几何概型, 积分)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=2321">https://uva ...