Chef and The Right Triangles

The Chef is given a list of N triangles. Each triangle is identfied by the coordinates of its three corners in the 2-D cartesian plane. His job is to figure out how 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 integer N denoting the number of triangles. Each of the following N

lines contain six space separated integers x1 y1 x2 y2 x3 y3 where (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

  • 1 ≤ N ≤ 100000 (105)
  • 0 ≤ x1, y1, x2, y2, x3, y3 ≤ 20

Example

Input:
5
0 5 19 5 0 0
17 19 12 16 19 0
5 14 6 13 8 7
0 4 0 14 3 14
0 2 0 14 9 2 Output:
3

推断是否是直角三角形,两种方法:

1 a*a + b*b = c*c

2 A dot B == 0  //dot是向量的点乘

重载操作符:

1 定义一个Point

2 定义Point的操作: 1) 减法  2) *乘号代表dot运算

#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;
}

最新文章

  1. 《PHP中的Math函数》笔记
  2. K线图学习
  3. eval函数的工作原理
  4. Ios 弹框 MJPopup,KxMenu
  5. MFC编程入门
  6. uva 11987 Almost Union-Find (并检查集合)
  7. 2.2 Xpath-helper (chrome插件) 爬虫、网页分析解析辅助工具
  8. LightOJ 1370 Bi-shoe and Phi-shoe 数论
  9. java实现简单的单点登录_转
  10. mssql sqlserver存储过程专题
  11. 【读书笔记】iOS-UDID
  12. ​ 别忘了Nologging哦
  13. Windows版Mycat结合mysql安装配置+水平切分(转载)
  14. mybatis一对一和一对多实例
  15. mysql多实例安装与ssl认证
  16. JNI 详细使用 基础【步骤】
  17. 安装Office2007时出现1706错误的解决方案
  18. Java-idea-生成JavaDoc
  19. Linux启动U盘制作
  20. vue 之 表单输入绑定

热门文章

  1. Asp.net MVC1 学习1
  2. Delphi XE6调用javascript
  3. 谈谈ILDasm的功能限制与解除
  4. 第一章 andriod studio 安装与环境搭建
  5. android TextView 带滚动条,和ScrollView 用法(暂时觉得ScrollView滑动速度比较快)
  6. CC++初学者编程教程(11) 配置Windows数据库服务器
  7. 【Daily】 2014-4-23
  8. STL 统计vector容器中指定对象元素出现的次数:count()与count_if()算法
  9. Ubuntu12.04下eclipse提示框黑色背景色的修改方法
  10. ubuntu 下 apache+tomcat整合_(mod-jk方法)[转]