64-bit integer IO format: %lld Java class name: Main
The king found his adherents were building four sanctuaries for him. He is interested about the positions of the sanctuaries and wants to know whether they would form a parallelogram, rectangle, diamond, square or anything else.
Input
The first line of the input is T(1 <= T <= 1000), which stands for the number of test cases you need to solve.
Each case contains four lines, and there are two integers in each line, which shows the position of the four sanctuaries. And it is guaranteed that the positions are given clockwise. And it is always a convex polygon, if you connect the four points clockwise.
Output
For every test case, you should output "Case #t: " first, where t indicates the case number and counts from 1, then output the type of the quadrilateral.
Sample Input
5
0 0
1 1
2 1
1 0
0 0
0 1
2 1
2 0
0 0
2 1
4 0
2 -1
0 0
0 1
1 1
1 0
0 0
1 1
2 1
3 0
Sample Output
Case #1: Parallelogram
Case #2: Rectangle
Case #3: Diamond
Case #4: Square
Case #5: Others
谨以此题来纪念我今天的傻逼行为
http://www.bnuoj.com/v3/problem_show.php?pid=24259
题意: 顺时针给出四个点的坐标,判断能构成矩形 菱形 平行四边形 还是 正方形 或者其他
第一:判断重点,每两个点判断长度是否为0
第二:在判断是否都成直角时,想简单了,
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct Node
{
int x,y;
};
Node p[5];
long long len(Node x1,Node x2)
{
return (x1.x-x2.x)*(x1.x-x2.x)+(x1.y-x2.y)*(x1.y-x2.y);
}
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
for(int j=0;j<4;j++)
scanf("%d%d",&p[j].x,&p[j].y);
printf("Case #%d: ",i);
int flag=0;
for(int j=0;j<4;j++)
for(int k=j+1;k<4;k++)
{
if(len(p[j],p[k]) == 0)
{
flag=1;
break;
}
}
if( flag == 0 )
{
if( len(p[0],p[1] ) == len( p[1],p[2] ) && len( p[1],p[2] ) == len( p[2],p[3] ) && len( p[2],p[3]) == len( p[3],p[0]) && len( p[3],p[0] ) == len( p[1],p[0] ) )
{
//if(( p[0].x == p[1].x && p[0].y == p[3].y ) ||( p[0].y == p[1].y && p[0].x == p[3].x) ) 斜着垂直
if( len(p[0],p[2]) == len(p[1],p[3]) )
printf("Square\n");
else
printf("Diamond\n");
}
else
if(len( p[0],p[1]) == len( p[2],p[3] ) && len( p[0],p[3] ) == len( p[1],p[2]) )
{
//if( ( p[0].x == p[1].x && p[0].y == p[3].y ) || ( p[0].y == p[1].y && p[0].x == p[3].x ) )
if( len(p[0],p[2]) == len(p[1],p[3]) )
printf("Rectangle\n");
else
printf("Parallelogram\n");
}
else printf("Others\n");
}
else printf("Others\n");
}
return 0;
}