18A - Triangle - CodeForces Solution


brute force geometry *1500

Please click on ads to support us..

C++ Code:

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int distance(int a,int b,int x,int y){
	return ((a -x)*(a-x) + (b-y)*(b-y));
}

bool check(vector<int> cod){
	int d1,d2,d3;
	unsigned int i=0;
	for(i=0;i<cod.size();i+=1){
		cod[i]-=1;
		d1=distance(cod[0],cod[1],cod[2],cod[3]);
		d2=distance(cod[0],cod[1],cod[4],cod[5]);
		d3=distance(cod[2],cod[3],cod[4],cod[5]);
		cod[i]+=1;
		//cout<<d1<<" "<<d2<<" "<<d3<<endl;
		if(d1 == 0 or d2 ==0 or d3 == 0)
			continue;
		if( (d1 == d2 + d3) or (d2 == d1 + d3) or (d3 == d2 + d1)){
			//cout<<d1<<" "<<d2<<" "<<d3<<endl;
			return 1;
			}
	}
	for(i=0;i<cod.size();i+=1){
		cod[i]+=1;
		d1=distance(cod[0],cod[1],cod[2],cod[3]);
		d2=distance(cod[0],cod[1],cod[4],cod[5]);
		d3=distance(cod[2],cod[3],cod[4],cod[5]);
		//cout<<cod[0]<<" "<<cod[1]<<" "<<cod[2]<<" "<<cod[3]<<" "<<cod[4]<<" "<<cod[5]<<endl;
		//cout<<d1<<" "<<d2<<" "<<d3<<endl;
		cod[i]-=1;
		if(d1 == 0 or d2 ==0 or d3 == 0)
			continue;
		if( (d1 == d2 + d3) or (d2 == d1 + d3) or (d3 == d2 + d1)){
			//cout<<d1<<" "<<d2<<" "<<d3<<endl;
			return 1;
			}
	}
	return 0;
}

int main(){
	vector<int> cod;
	unsigned int i;
	for(i=0;i<6;i+=1){
		int temp;
		cin>>temp;
		cod.push_back(temp);
	}
	int d1,d2,d3;
	d1=distance(cod[0],cod[1],cod[2],cod[3]);
	d2=distance(cod[0],cod[1],cod[4],cod[5]);
	d3=distance(cod[2],cod[3],cod[4],cod[5]);
	//cout<<d1<<" "<<d2<<" "<<d3<<endl;
	if( (d1 == d2 + d3) or (d2 == d1 + d3) or (d3 == d2 + d1)){
		cout<<"RIGHT"<<endl;
		return 0;
		}
	else if( check(cod))
		cout<<"ALMOST"<<endl;
	else
		cout<<"NEITHER"<<endl;
	return 0;
}


Comments

Submit
0 Comments
More Questions

1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces
1607B - Odd Grasshopper
1084A - The Fair Nut and Elevator
1440B - Sum of Medians
1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction
1604B - XOR Specia-LIS-t
1606B - Update Files
1598B - Groups
1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array
2090. K Radius Subarray Averages
2091. Removing Minimum and Maximum From Array
6. Zigzag Conversion
1612B - Special Permutation
1481. Least Number of Unique Integers after K Removals
1035. Uncrossed Lines
328. Odd Even Linked List