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. Linux05--Shell程序设计01

    1.Shell脚本介绍 基本介绍: shell脚本是一个可执行的纯文本文件,由多个shell命令组成. 命令的执行是从上而下,从左而右的分析和执行 命令,参数间的多个空白也会被忽略 #是注释 #!用于 ...

  2. ODI 11g Studio 修改界面语言

    {ODI_HOME}/oracledi\client\ide\bin找到ide.conf 添加AddVMOption -Duser.language=enAddVMOption -Duser.regi ...

  3. 利用协议代理实现导航控制器UINavigationController视图之间的正向传值和反向传值

    实验说明 (1)正向传值:比如A类里地值要传给B类用,就是我们先在A类中声明一个B类对象(当然B类头文件要import过来),然后把A类中得某个 值传递给B类中得某个值(所以需要在B类中先准备一个变量 ...

  4. 关于在用Swift开发iOS时如何隐藏NavigationBar和TabBar

    举个例子:如果我有一个页面需要进入时同时隐藏NavigationBar和TabBar,那么我就在那个页面的ViewController的代码里加上下面的代码.就可以实现了.接下来告诉大家每一块要注意的 ...

  5. aps.net要掌握的技术

    Spring.Net.NHibernate.Entity Framework.ASP.Net MVC.HTML5.WCF.数据库集群.分布式应用集群.高性能读写NoSql

  6. Java基础笔记-异常

    Java中的异常机制: Throwable类是 Java 语言中所有错误或异常的超类.主要包括两个子类: Error和Exception. 一般中要处理的异常是Exception. Java中最常见的 ...

  7. hadoop 学习

    不同版本间Hadoop拷贝 通过NFS,将hdfs挂在到本地

  8. C++ 数据结构学习二(单链表)

    模板类 //LinkList.h 单链表#ifndef LINK_LIST_HXX#define LINK_LIST_HXX#include <iostream>using namespa ...

  9. cookie记录用户的浏览商品的路径

    在电子商务的网站中,经常要记录用户的浏览路径,以判断用户到底对哪些商品感兴趣,或者哪些商品之间存在关联. 下面将使用cookie记录用户的浏览过的历史页面.该网站将每个页面的标题保存在该页面的$TIT ...

  10. RelativeLayout布局下实现控件平分空间

    起源:使用惯LinearLayout的朋友都知道,若想实现对屏幕的等分,只需要设置Layout_weight的值即可. 可是在RelativeLayout布局下实现等分却不是那么容易. 下面就简单介绍 ...