Codechef chef and the right triangles

Source: Internet
Author: User
Tags x2 y2

Chef and the right triangles

The chef is given a listN triangles. Each triangle is identfied by the coordinates of its three corners in the 2-D cartesian plane. His job is to figure outHow many
Of the given triangles are right triangles
. A right triangle is a triangle in which one angle is a 90 degree angle. The vertices
Of the triangles have integer coordinates and all the triangles given are valid (three points aren't colinear ).

 

Input

The first line of the input contains an integerNDenoting the number of triangles. Each of the followingN
Lines contain six space separated IntegersX1 Y1 X2 Y2 X3 Y3Where(X1, Y1),
(X2, Y2)And(X3, Y3)Are the vertices of a triangle.

 

Output

Output one integer, the number of right triangles among the given triangles.

 

Constraints
  • 1N100000 (105)
  • 0X1, Y1, X2, Y2, X3, Y320

 

Example
Input:50 5 19 5 0 017 19 12 16 19 05 14 6 13 8 70 4 0 14 3 140 2 0 14 9 2Output:3

Two ways to infer whether a right triangle is used:

1 A * A + B * B = C * C

2 A dot B = 0 // dot is the point multiplication of the vector.


Overload OPERATOR:

1 define a point

2 define the point operation: 1) subtraction 2) * multiplication represents the dot operation


#pragma once#include <stdio.h>class ChefandTheRightTriangles{struct Point{int x, y;explicit Point(int a = 0, int b = 0): x(a), y(b) {}Point operator-(const Point &p) const{return Point(x - p.x, y - p.y);}int operator*(const Point &p) const{return x * p.x + y * p.y;}};int getInt(){char c = getchar();while (c < ‘0‘ || ‘9‘ < c){c = getchar();}int num = 0;while (‘0‘ <= c && c <= ‘9‘){num = (num<<3) + (num<<1) + (c - ‘0‘);c = getchar();}return num;}public:ChefandTheRightTriangles(){int N = 0, C = 0;N = getInt();Point p1, p2, p3, v1, v2, v3;while (N--){p1.x = getInt(), p1.y = getInt();p2.x = getInt(), p2.y = getInt();p3.x = getInt(), p3.y = getInt();v1 = p1 - p2, v2 = p2 - p3, v3 = p3 - p1;if (v1 * v2 == 0 || v2 * v3 == 0 || v3 * v1 == 0)C++;}printf("%d", C);}};int chefandTheRightTriangles(){ChefandTheRightTriangles();return 0;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.