King's Sanctuary
来源:互联网 发布:手机淘宝怎么看优惠券 编辑:程序博客网 时间:2024/04/30 09:56
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;}
- King's Sanctuary
- CDOJ King's Sanctuary 几何
- UESTC 93 King's Sanctuary 基础
- sdau 省赛热身4 K - King's Sanctuary
- 弱校联萌十一大决战之背水一战K. King's Sanctuary
- CDOJ 93 King's Sanctuary【判断四边形形状】
- King's Man
- 1904 King's Quest
- PKU1904 king's quest
- poj1904 - King's Quest
- hdu3861The King’s Problem
- hdu3861The King’s Problem
- King's Cake
- hdu5641 king's phone
- hdu----King's Phone
- hdu5642 King's Order
- King's Phone
- King's Cake
- 分布式RAM
- 第三十篇:控制器的生成与多控制器的管理
- 父类子类之间的一个经典题目(有关成员变量何时赋值和在哪里赋值的问题)
- 数塔DP
- pygame编写的坦克游戏(一)
- King's Sanctuary
- cf#324 Div.2 Problem C Marina and Vasya
- [LeetCode-160] Intersection of Two Linked Lists(找到两链表公共交叉点)
- [面试金典]顺时针打印矩阵
- 全局变量和局部变量
- Java学习笔记———《http的get请求和post请求及封装的工具类》
- 图片如何通过ps更加清晰
- cf#324 Div.2 Problem D Dima and Lisa
- 学习记录——记忆化搜索 A* POJ2449 Remmarguts' Date