UVA11800--Determine the Shape(计算几何)
来源:互联网 发布:php项目文档 编辑:程序博客网 时间:2024/05/21 22:49
G
Determine the Shape
Input
Standard Input
Output
Standard Output
A toy company recently found that toys like revolver, machine guns, fighting planes are making children violent and destroying the peace of the world. The parents also began to avoid these toys and inclined to educational toys. So they decided to manufacture educational toys. One of these is a electric touch pad on which children can put four points and the program will automatically join the points to form a closed shape. Children will try to guess the shape and when they press a button then it will automatically announce the shape. But they are struggling to determine the shape and seek your help.
Your task is simple. You are given four points, no three of them are collinear, you have to output the simple polygonal shape formed by these points in the following order:
Square
Rectangle
Rhombus
Parallelogram
Trapezium
Ordinary Quadrilateral
For example if it is possible to form a square with the four points you must output ‘Square’, if it is not possible to form a square but possible to form a rectangle you must output ‘Rectangle’ and so on.
Input
Input starts with an integer T, the number of test cases (T≤50000). Each test case contains 4 lines. Each of the lines contains two space separated integersxi yi (-10000≤xi, yi≤ 10000) which are the coordinate values of a point.
Output
For each set of input output one line in the format “Case k: s”. Here k is the case number starting from 1 ands is the shape as described above. See sample input output for more details.
Sample Input
Sample Output
6
0 0
2 0
2 2
0 2
0 0
3 0
3 2
0 2
0 0
8 4
5 0
3 4
0 0
2 0
3 2
1 2
0 0
5 0
4 3
1 3
0 0
5 0
4 3
1 4
Case 1: Square
Case 2: Rectangle
Case 3: Rhombus
Case 4: Parallelogram
Case 5: Trapezium
Case 6: Ordinary Quadrilateral
给出四个点,求出四点连线的四边形是什么类型的~
T^T 因为长方形的单词复制错了WA了N多遍,555555~~~~~~~~~
CODE:
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <string>#include <cstring>#include <queue>#include <stack>#include <vector>#include <set>#include <map>const int inf=0xfffffff;typedef long long ll;using namespace std;//const ll pai=acos(-1.0);char s[][25]={"","Square","Rectangle","Rhombus","Parallelogram","Trapezium","Ordinary Quadrilateral"};struct node{ ll x,y; bool operator<(const node &a)const{ if(x==a.x) return y<a.y; return x<a.x; }}fan[4];bool cmp(node a,node b){ if(a.x == b.x) return a.y<b.y; return a.x<b.x;}ll len(node a,node b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}int angle_90(node a,node b,node c,node d){ ll x1=a.x-b.x, y1=a.y-b.y, x2=c.x-d.x, y2=c.y-d.y; if((x1*x2+y1*y2)==0) return 1; return 0;}int angle_0(node a,node b,node c,node d){ ll x1=a.x-b.x, y1=a.y-b.y, x2=c.x-d.x, y2=c.y-d.y; if(x1*y2==x2*y1) return 1; return 0;}int work(){ ll a=len(fan[0],fan[1]), b=len(fan[1],fan[2]), c=len(fan[2],fan[3]), d=len(fan[3],fan[0]); int ang1=angle_90(fan[0],fan[1],fan[2],fan[1]), ang2=angle_90(fan[1],fan[2],fan[3],fan[2]), ang3=angle_90(fan[2],fan[3],fan[0],fan[3]), ang4=angle_90(fan[3],fan[0],fan[1],fan[0]), op=angle_90(fan[0],fan[2],fan[1],fan[3]), par1=angle_0(fan[0],fan[1],fan[3],fan[2]), par2=angle_0(fan[1],fan[2],fan[0],fan[3]); if(a==b && b==c && c==d && d==a && (ang1+ang2+ang3+ang4)==4) return 1; //正方形 if(a==c && b==d && a!=b && ang1 && ang2 && ang3 && ang4) return 2; //长方形 if(a==b && b==c && c==d && d==a && op && par1 && par2 && (ang1+ang2+ang3+ang4)==0) return 3; //菱形 if(a==c && b==d && par1 && par2) return 4; //平行四边形 if(a!=c && par1 && par2==0) return 5; // 梯形 return 0;}int main(){ //freopen("in.in","r",stdin); int N; scanf("%d",&N); for(int nn=1;nn<=N;nn++){ for(int i=0;i<4;i++){ scanf("%lld%lld",&fan[i].x,&fan[i].y); } int ok=1; do{ if(work()!=0){ printf("Case %d: %s\n",nn,s[work()]); ok=0; break; } }while(next_permutation(fan,fan+4,cmp)); if(ok) printf("Case %d: %s\n",nn,s[6]); } return 0;}
- UVA11800--Determine the Shape(计算几何)
- UVA11800 Determine the Shape
- UVA11800 - Determine the Shape
- [UVA]11800-Determine the Shape(计算几何)
- UVA 11800 - Determine the Shape(计算几何)
- uva 11800 Determine the Shape 判断四边形形状(计算几何)
- UVA 11800 —— Determine the Shape(几何基础)
- UVA 11800 - Determine the Shape 几何
- UVa 11800 Determine the Shape(几何)
- 几何 入门题 UVA 11800 - Determine the Shape
- UVa 11800 - Determine the Shape
- uva 11800 - Determine the Shape
- UVA 11800 Determine the Shape
- UVa 11800 Determine the Shape
- UVA 11800 - Determine the Shape
- uva 11800 - Determine the Shape
- UVA 11800 Determine the Shape
- UVa 11800 - Determine the Shape
- golang.org进不去
- leetcode 刷题之路 84 Single Number II
- jquery 实现iframe 自适应高度
- Dialog的ID重复
- 学习OpenGL(三)绘制螺旋状图形
- UVA11800--Determine the Shape(计算几何)
- 将一个文件作为下载的形式打开【下载文件】,添加报文头context.Response.AddHeader("Content-disposition", "attachment; filename="
- 从java网络编程学起(3)
- Spring MVC过滤器 登陆过滤
- OpenStack install for RedHAT linux(概述)
- 关于Chronometer(计时器)暂停的问题
- 对比两张表中不一致的字段
- MediaPlayer播放失败,打包失败
- Equivalent of CONTAINS and LIKE in an IF statement