Tuesday, January 28, 2014

codechef RIGHTRI - "chef and the right triangles" solution

codechef RIGHTRI - "chef and the right triangles" : http://www.codechef.com/problems/RIGHTRI
codechef RIGHTRI - "chef and the right triangles" editorial :  http://discuss.codechef.com/questions/21667/rightri-editorial

codechef RIGHTRI - "chef and the right triangles" solution :  http://ideone.com/y4pOmO

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
int n, x1, y1, x2, y2, x3, y3, cnt;
scanf("%d", &n); 
cnt=0;
while(n--) {
scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
if (((y2-y1)*(y3-y2))==-((x2-x1)*(x3-x2)))
cnt++;
else if (((y1-y2)*(y3-y1))==-((x1-x2)*(x3-x1)))
cnt++;
else if (((y3-y1)*(y2-y3))==-((x3-x1)*(x2-x3)))
cnt++;
}
printf("%d", cnt);
return 0;
}

note: when angle is right, it means that two lines are perpendicular, which means that one angle is 90 degree, so how we know whether any two lines are perpendicular or not, by calculating their slope:  http://www.mathsisfun.com/gradient.html

2 comments: