codechef Chef and The Right Triangles 题解
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 题解的更多相关文章
- CodeChef:Chef and Problems(分块)
CodeChef:Chef and Problems 题目大意 有一个长度为n的序列$a_1,a_2,……,a_n$,每次给出一个区间[l,r],求在区间内两个相等的数的最远距离($max(j-i,满 ...
- 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]) ...
- CODECHEF Chef and Churus 解题报告
[CODECHEF]Chef and Churus Description 有一个长度为\(n\)的数组\(A\),有\(n\)个函数,第\(i\)个函数的值为\(\sum_{j=l_i}^{r_i} ...
- CodeChef Chef and Churu [分块]
题意: 单点修改$a$ 询问$a$的区间和$f$的区间和 原来普通计算机是这道题改编的吧... 对$f$分块,预处理$c[i][j]$为块i中$a_j$出现几次,$O(NH(N))$,只要每个块差分加 ...
- codechef Chef And Easy Xor Queries
做法:我们考虑前缀异或和,修改操作就变成了区间[i,n]都异或x 查询操作就变成了:区间[1,x]中有几个k 显然的分块,每个块打一个tag标记表示这个块中所有的元素都异或了tag[x] 然后处理出这 ...
- 2019.02.14 codechef Chef at the Food Fair(线段树+泰勒展开)
传送门 题意:现在有nnn个位置,每个位置上有一个值aia_iai. 要求支持如下两种操作: 区间乘vvv 求区间的(1−ai)(1-a_i)(1−ai)之积 思路: 考虑转换式子: Ans=∏i ...
- 【A* 网络流】codechef Chef and Cut
高嘉煊讲的杂题:A*和网络流的练手题 题目大意 https://s3.amazonaws.com/codechef_shared/download/translated/SEPT16/mandarin ...
- codechef Chef and Problems
终于补出这道:一直耽搁到现在 找到一个代码可读性很好的分块temp; 题意:给一个长度为n 的数组 A,Q次询问,区间相等数的最大范围是多少? 数据范围都是10e5; 当然知道分块了: 传统分块看各种 ...
- Codechef Chef Cuts Tree
该思博的时候就思博到底,套路的时候不能再套路的一道题 首先我们将联通块的大小平方和进行转化,发现它就等价于连通点对数,而这个可以转化为连接两点的边数(距离)和 所以我们考虑第\(i\)天时,一个点对\ ...
随机推荐
- UML-状态图,顺序图,活动图
一.编写用例文档 1.用例的内容: 用例编号 用例名 执行者 前置条件 后置条件 基本路径 扩展路径 字段列表 业务规则 ...
- QStringList不是简单重命名的便利类,而是提供了额外的函数,比如sort和join等等
以前一直以为就是重命名而已,原来还不是.QT真伟大,方便到家了.该有的,全都有现成的.
- 【Itext】7步制作Itext5页眉页脚pdf实现第几页共几页
itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类 ...
- 安装Logstash
安装Logstash: Logstash 需要 Java 7或者以后版本,使用官方的Oracle发布或者一个开源发布版本比如OpenJDK 检查Java 版本,运行下面的命令: zjtest7-fro ...
- 学javascript突发奇想,只用浏览器就能转换进制
只需要三行就可以了 具体代码如下 <script> document.write(new Number(8).toString(2));//toSting方法可以转换任何进制 </s ...
- C# 分析搜索引擎url 得到搜索关键字
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Effective C++笔记 55条编程法则
1. 视C++为一个语言联邦 C++高效编程守则视状况而变化,取决于你使用C++的哪一部分. 2. 尽量以const,enum.inline替代#define 1) 对于单纯常量,最好以const ...
- 【玩转Ubuntu】01. Ubuntu上配置JDK
一.安装JDK 提示:这里我们使用jdk1.6,因为android开发要求使用1.6.如果不信你可以打开android studio,它会提示你选择JDK6的路径 下载地址: http://www.o ...
- [ACM] hdu 2191 珍惜如今,感恩生活 (多重背包)
Problem Description 急!灾区的食物依旧短缺! 为了拯救灾区同胞的生命,心系灾区同胞的你准备自己採购一些粮食支援灾区,如今如果你一共同拥有资金n元,而市场有m种大米,每种大米都是袋装 ...
- C语言中为什么不能把char**赋给const char**
这是我在知乎回答的一个问题. 这个问题是C中的一个深坑,首先说结论: char ** 和 const char ** 是两个不相容(incompatible)的类型,能够理解为不能直接赋值 在C11的 ...