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

codechef Chef and The Right Triangles 题解的更多相关文章

  1. CodeChef:Chef and Problems(分块)

    CodeChef:Chef and Problems 题目大意 有一个长度为n的序列$a_1,a_2,……,a_n$,每次给出一个区间[l,r],求在区间内两个相等的数的最远距离($max(j-i,满 ...

  2. Codechef Chef and Triangles(离散化+区间并集)

    题目链接 Chef and Triangles 先排序,然后得到$m - 1$个区间: $(a[2] - a[1], a[2] + a[1])$ $(a[3] - a[2], a[3] + a[2]) ...

  3. CODECHEF Chef and Churus 解题报告

    [CODECHEF]Chef and Churus Description 有一个长度为\(n\)的数组\(A\),有\(n\)个函数,第\(i\)个函数的值为\(\sum_{j=l_i}^{r_i} ...

  4. CodeChef Chef and Churu [分块]

    题意: 单点修改$a$ 询问$a$的区间和$f$的区间和 原来普通计算机是这道题改编的吧... 对$f$分块,预处理$c[i][j]$为块i中$a_j$出现几次,$O(NH(N))$,只要每个块差分加 ...

  5. codechef Chef And Easy Xor Queries

    做法:我们考虑前缀异或和,修改操作就变成了区间[i,n]都异或x 查询操作就变成了:区间[1,x]中有几个k 显然的分块,每个块打一个tag标记表示这个块中所有的元素都异或了tag[x] 然后处理出这 ...

  6. 2019.02.14 codechef Chef at the Food Fair(线段树+泰勒展开)

    传送门 题意:现在有nnn个位置,每个位置上有一个值aia_iai​. 要求支持如下两种操作: 区间乘vvv 求区间的(1−ai)(1-a_i)(1−ai​)之积 思路: 考虑转换式子: Ans=∏i ...

  7. 【A* 网络流】codechef Chef and Cut

    高嘉煊讲的杂题:A*和网络流的练手题 题目大意 https://s3.amazonaws.com/codechef_shared/download/translated/SEPT16/mandarin ...

  8. codechef Chef and Problems

    终于补出这道:一直耽搁到现在 找到一个代码可读性很好的分块temp; 题意:给一个长度为n 的数组 A,Q次询问,区间相等数的最大范围是多少? 数据范围都是10e5; 当然知道分块了: 传统分块看各种 ...

  9. Codechef Chef Cuts Tree

    该思博的时候就思博到底,套路的时候不能再套路的一道题 首先我们将联通块的大小平方和进行转化,发现它就等价于连通点对数,而这个可以转化为连接两点的边数(距离)和 所以我们考虑第\(i\)天时,一个点对\ ...

随机推荐

  1. Static Function Test

    public class StaticTestCls { public int x = 0; public static int y = 0; private void SetValue_Object ...

  2. Struts2五、Struts1与Struts2的区别

    Struts1和Struts2的区别和对比: Action 类:  • Struts1要求Action类继承一个抽象基类.Struts1的一个普遍问题是使用抽象类编程而不是接口,而struts2的Ac ...

  3. Linux学习之十一、环境变量的功能

    环境变量的功能 可以利用两个命令来查阅,分别是 env 与 export 呢! 范例一:列出目前的 shell 环境下的所有环境变量与其内容. [root@www ~]# env SHELL 告知我们 ...

  4. javascript第五课表达式

    c#常用的表达式,一般这里都能用上 例如:三元表达式 var text=20>8? 真 : 假;  表达式?true:flase

  5. C#复制数据库,将数据库数据转到还有一个数据库

    本文章以一个表为例,要转多个表则可将DataSet关联多个表.以下给出完整代码.包含引用以及main函数与复制函数. 要说明的是,必须先用Sql语句复制表结构,才干顺利的使用下面代码复制数据. usi ...

  6. UVALive 3635 Pie 切糕大师 二分

    题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的. 做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又 ...

  7. 3.C#/.NET编程中的常见异常(持续更新)

    1.Object reference not set to an instance of an object. 未将对象引用(引用)到对象的实例,说白了就是有个对象为null,但是你在用它点出来的各种 ...

  8. JavaScript之JSON

    一.简介:Json是JavaScript中读取结构化数据更好的方式.因为Json数据可以直接传给eval(),而且不必创建DOM对象.Json是一种数据格式,不是一种编程语言,虽然具有相同的语法形式, ...

  9. SharePoint 2013 强制安装解决方案

    Add-SPSolution Install-SPSolution -Identity DemonstrationZone.wsp -GACDeployment -CompatibilityLevel ...

  10. Mantis 缺陷管理系统配置与安装[Z]

    什么是Mantis MantisBT is a free popular web-based bugtracking system (feature list). It is written in t ...