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 integers xi 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 and s 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
|
题意:
给出 4 个点的坐标,输出这是 正方形,长方形,平行四边形,梯形,普通三角形 还是 菱形。
思路:
暴力。输出的坐标可以先预处理一下,x 轴小到大排序,再 y 小到大排序。对于正方形,长方形,平行四边形,菱形都是可以直接判断的,但是梯形的话就要判断任意两条边平行,剩下两条边不平行来判断。如果全都不是,则说明是普通三角形。
AC:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; typedef struct { ll x, y; }node; ll len(ll x1, ll y1, ll x2, ll y2) { ll x = (x2 - x1) * (x2 - x1); ll y = (y2 - y1) * (y2 - y1); return (x + y); } bool ang(node a, node b, node c, node d) { ll x1 = a.x - b.x, y1 = a.y - b.y; ll x2 = c.x - d.x, y2 = c.y - d.y; if (x1 * x2 + y1 * y2 == 0) return true; return false; } bool par(node a, node b, node c, node d) { ll x1 = a.x - b.x, y1 = a.y - b.y; ll x2 = c.x - d.x, y2 = c.y - d.y; if (x1 * y2 - x2 * y1 == 0) return true; return false; } bool Trapezium(node a, node b, node c, node d) { if (par(a, b, c, d) && !par(a, c, b, d)) return true; if (par(a, c, b, d) && !par(a, b, c, d)) return true; if (par(b, c, d, a) && !par(b, d, c, a)) return true; return false; } bool cmp(node a, node b) { if (a.x != b.x) return a.x < b.x; return a.y < b.y; } int main() { int t; scanf("%d", &t); for (int tt = 1; tt <= t; ++tt) { node no[5]; for (int i = 1; i <= 4; ++i) scanf("%lld%lld", &no[i].x, &no[i].y); sort(no + 1, no + 5, cmp); ll len1 = len(no[1].x, no[1].y, no[2].x, no[2].y); ll len2 = len(no[1].x, no[1].y, no[3].x, no[3].y); ll len3 = len(no[2].x, no[2].y, no[4].x, no[4].y); ll len4 = len(no[3].x, no[3].y, no[4].x, no[4].y); printf("Case %d: ", tt); if (len1 == len2 && len3 == len4 && len1 == len4 && ang(no[2], no[1], no[3], no[1]) && ang(no[1], no[2], no[4], no[2]) && ang(no[1], no[3], no[4], no[3]) && ang(no[2], no[4], no[3], no[4]) ) printf("Square\n"); else if (len1 == len4 && len2 == len3 && len1 != len2 && ang(no[2], no[1], no[3], no[1]) && ang(no[1], no[2], no[4], no[2]) && ang(no[1], no[3], no[4], no[3]) && ang(no[2], no[4], no[3], no[4]) ) printf("Rectangle\n"); else if (len1 == len4 && len2 == len3 && len1 == len2 && ang(no[3], no[2], no[4], no[1])) printf("Rhombus\n"); else if (par(no[4], no[2], no[3], no[1]) && par(no[2], no[1], no[4], no[3])) printf("Parallelogram\n"); else if (Trapezium(no[1], no[2], no[3], no[4])) printf("Trapezium\n"); else printf("Ordinary Quadrilateral\n"); } return 0; }
相关推荐
kmeans determine the frequency
When the past no longer illuminates the future, people will wander in the dark
标题 "The skin does not exist: Unable to determine the release version" 提到的问题,通常是与软件部署或更新时出现的错误有关,尤其是与版本控制或者界面显示有关。这可能是指在使用某些开源工具或框架时,系统...
"Determine-the-type-of-drive.rar_The Drive" 这个压缩包文件提供了关于识别计算机驱动器类型以及操作系统位数的方法。这里我们将深入探讨如何确定驱动器类型(硬盘、移动磁盘或光驱)以及如何辨别系统是32位还是64...
Different color spaces are explored to determine the most effective representation for tracking. - **Tracking**: The ASM is then fitted to the image sequence using iterative optimization techniques....
### 如何确定已安装在Catalyst 6500/6000系列交换机中的主管模块类型 #### 引言 本文档提供了一些简单的检查步骤,以便您能够确定Cisco Catalyst 6000或6500系列交换机所使用的主管引擎模块的类型。...
JEDEC JESD33B:2004(R2018) Standard Method for Measuring and Using the Temperature Coefficient of Resistance to Determine the Temperature of a Metallization Line JEDEC JESD33B标准是由JEDECSolid ...
Enter a three-digit number to determine whether the number is a daffodil number or not, and output t.zip
### 使用SAS确定新兴产品对收入的影响 #### 摘要 本文介绍了一种利用SAS软件来评估新兴产品——特别是天然气壁炉和木炭(统称为“壁炉产品”)——对天然气销售额影响的方法。自1990年以来,消费者对这类产品的需求...
browser.js判断浏览器和内核的工具(Determine the browser and the kernel of the tool)Date: 2015-07-25首先引入browser.js 返回 client 对象:client 对象下有两个对象:engine 和 browser,如下://呈现引擎var...
ectively determine the contact condition and contact point without solving the simultaneous equations of the two ellipsoidal surfaces. Each particle's packing location, contact-point co-ordinates, and...
like operating system package possible, with due respect to the original software tools ideology as well as usability, performance and stability.” The architectural guidelines help determine whether ...
"Determine if a Directory Exists"这个主题就涉及到了如何检查计算机系统中是否存在特定的目录。这是一个基础但至关重要的功能,因为它广泛应用于文件管理、数据备份、安装程序验证等多个场景。 在Windows操作系统...
The relations between the two is by the camera model to determine the imaging geometry, that is to determine the parameters of the camera. Zhang is achieved and the Friends of the matlab calibration ...
在开发Windows Forms或Web应用程序时,常常需要对用户输入的数据进行验证,确保它们符合预期的格式。例如,如果我们有一个TextBox控件,希望用户输入的是一个整数,我们就需要编写代码来检查输入的内容是否为数字,...
4. Determine the outline(s) of characters of the image. 5. Segment the image to separate and label the different characters. 6. Arrange the characters in one line with the sequence: AB123C 7. Rotate ...
高中英语知识点大全43 determine、devote、delight的用法 在高中英语学习中,掌握好etermine、devote、delight三个词的用法是非常重要的。本文将对这三个词的用法进行详细的讲解。 一、determine determine是一个...
But because the gear relative to the bearing of the two-stage cylindrical gear reducer is arranged asymmetrically, the load distribution along the tooth direction is uneven, and the shaft stiffness ...