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\)天时,一个点对\ ...
随机推荐
- PBM文件格式
PBM是一种单色位图文件,常用于打印机,由于需要下面对PBM文件格式进行分析. 每个文件的开头两个字节(ASCII码)作为文件描述子,可以理解为文件头.具体如下: 头 类型 编码 P1 位图 ASCI ...
- OTG中的ID脚风波释疑
1. 概要 OTG设备使用插头中的ID引脚来区分A/B Device,ID接地被称作为A-Device,充当USB Host,A-Device始终为总线提供电力,ID悬空被称作为B-Device,充当 ...
- SELinux开关导致mysql服务启动不了
http://www.jb51.net/article/36187.htm 网站突然连接不上数据库,于是朋友直接重启了一下服务器.进到cli模式下,执行 service myqsld start 发现 ...
- CSS制作出绚丽燃烧的火狐狸
From here:http://www.webhek.com/firefox-animation/ ozilla在移动世界大会上宣布它的火狐操作系统(Firefox OS)的同时,也宣布了它的合作伙 ...
- 【HDU】4923 Room and Moor(2014多校第六场1003)
Room and Moor Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 关于我们-成功人士西装定制服务第一品牌派斯特PAISTETAILOR绅士礼服
关于我们-成功人士西装定制服务第一品牌派斯特PAISTETAILOR绅士礼服 北京派思特服装服饰有限公司国内领先绅士男装定制品牌PAISTETAILOR,引领男装定制的领航者.
- UITableView进阶,cell刷新,界面返回 保持所选cell
1.cell 刷新 NSIndexPath *indexPath_1=[NSIndexPath indexPathForRow:1 inSection:0]; NSArray *indexArray= ...
- ASP.NET mvc4 WEB API异常处理
当一个web api抛出一个异常后 此异常会被转化成一个HTTP响应 错误代码为500的服务错误 但是如果你不想让客户端看到500的错误码 你也可以自定义错误码 如下代码当用户输入的ID没有与之相关的 ...
- Android开发8:UI组件TextView,EditText,Button
版本:Android4.3 API18 学习整理:liuxinming TextView 概述 TextView直接继承了View(EditText.Button两个UI组件类的父类) TextVie ...
- 解决itunesconnect无法訪问
今天打开https://itunesconnect.apple.com出现了无法訪问提示,例如以下图, 我起初以为苹果在维护呢,但想想,假设是维护提示页面也应该会友好些.带着疑问,google一搜,看 ...