King's Sanctuary(简单几何)
2013-07-28 09:45
141 查看
King's Sanctuary
Time Limit: 1000 ms Memory Limit: 65535 kB Solved: 111 Tried: 840
Submit
Status
Best Solution
Back
Description
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
50 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: ParallelogramCase #2: Rectangle
Case #3: Diamond
Case #4: Square
Case #5: Others
Source
Sichuan State Programming Contest 2012步骤:1.判断是否平行四边形,不是则为others,是则执行2;2.判断是否菱形,是否长方形,都是则为正方形,都不是则为平行四边形,其一是另一否,则是菱形或长方形。
#include <iostream> #include <queue> #include <vector> #include <map> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; int T, x[4], y[4]; bool Parallelogram() { int a = (y[1] - y[0]) * (x[3] - x[2]); int b = (x[1] - x[0]) * (y[3] - y[2]); if(a != b) return false; a = (x[2] - x[1]) * (y[3] - y[0]); b = (x[3] - x[0]) * (y[2] - y[1]); return a == b; } bool Rectangle() { int a = (x[0] - x[2]) * (x[0] - x[2]) + (y[0] - y[2]) * (y[0] - y[2]); int b = (x[1] - x[3]) * (x[1] - x[3]) + (y[1] - y[3]) * (y[1] - y[3]); return a == b; } bool Diamond() { int a = (y[0] - y[2]) * (y[1] - y[3]); int b = (x[1] - x[3]) * (x[0] - x[2]); return a == -b; } int main() { scanf("%d", &T); for(int ca = 1; ca <= T; ca++) { int i, j; for(i = 0; i < 4; i++) { scanf("%d %d", &x[i], &y[i]); } printf("Case #%d: ", ca); for(i = 0; i < 4; i++) { for(j = i + 1; j < 4; j++) { if(x[i] == x[j] && y[i] == y[j]) break; } if(j != 4) break; } if(i != 4) puts("Others"); else { bool tag, tag1; tag = Parallelogram(); if(tag == false) {puts("Others");} else { tag = Rectangle(); tag1 = Diamond(); if(tag == false && tag1 == false) puts("Parallelogram"); else if(tag == true && tag1 == true) puts("Square"); else if(tag == true) puts("Rectangle"); else if(tag1 == true) puts("Diamond"); } } } return 0; }
相关文章推荐
- cdoj 93 King's Sanctuary 傻逼几何题
- hdu5533Dancing Stars on Me(简单计算几何)
- Codeforces 618C Constellation(简单几何题—叉积)
- hdoj--5563--Clarke and five-pointed star(简单几何)
- OpenGL_Qt学习笔记之_02(绘制简单平面几何图形)
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) C. Constellation(思维 简单几何)
- zzulioj--1805-- SC和ta的游泳池(简单几何)
- 简单几何(线段相交) POJ 1410 Intersection
- 简单几何(线段相交) POJ 2826 An Easy Problem?!
- Ural-1020. Rope(简单计算几何)
- HDU 4720 Naive and Silly Muggles (简单计算几何)
- zzulioj--1600--直线与圆(简单数学几何)
- POJ2318 计算几何简单题
- 简单几何(水)BestCoder Round #50 (div.2) 1002 Run
- Sicily 1206. Stacking Cylinders | 使用STL的complex库实现简单几何
- cf13B Letter A(分类+简单计算几何,,)
- hdoj--5563--Clarke and five-pointed star(简单几何)
- 简单几何(直线与圆的交点) ZOJ Collision 3728
- Ogre 如何渲染简单的几何物体
- codeforces 394E Lightbulb for Minister 简单几何