In this HackerEarth Couting Triangles problem solution, You are given n triangles.

You are required to find how many triangles are unique out of given triangles. For each triangle you are given three integers a,b,c , the sides of a triangle.

A triangle is said to be unique if there is no other triangle with same set of sides.


HackerEarth Counting Triangles problem solution


HackerEarth Counting Triangles problem solution.

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<fstream>
#include<cstdlib>
#include<cassert>
#include<vector>
#include<algorithm>
#include<stack>
#include<set>
#include<map>
#include<list>
#include<math.h>
#include<ctime>
#define LL long long
#define ULL unsigned long long
#define F firs
#define S second
#define pb push_back
#define FOR(i,lb,ub) for(i=lb;i<=ub;i++)
#define RFOR(i,ub,lb) for(i=ub;i>=lb;i--)
#define FORS(it,v) for(it=v.begin();it!=v.end();it++)
#define st_clk double st=clock();
#define end_clk double en=clock();
#define show_time cout<<"\tTIME="<<(en-st)/CLOCKS_PER_SEC<<endl;
#define sc(n) scanf("%d",&n)
#define scst(n) scanf("%s",n)
#define f_in(st) freopen(st,"r",stdin);
#define f_out(st) freopen(st,"w",stdout);
LL gcd(LL a, LL b) { return b?gcd(b,a%b):a; }
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
int no;
cin>>no;
char istr[20],ostr[20];
sprintf(istr,"input-%d.txt",no);
sprintf(ostr,"out-%d.txt",no);
f_in(istr);
f_out(ostr);
#endif
int n,i,j;
cin>>n;

map<pair<LL,pair<LL,LL> >,int> container;
map<pair<LL,pair<LL,LL> >,int>::iterator it;
while (n--)
{
LL a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
assert(a[0]+a[1]>a[2]);
pair<LL,pair<LL,LL> > pp = make_pair(a[0],make_pair(a[1],a[2]));
it = container.find(pp);
if (it == container.end())
{
container.insert(make_pair(pp,0));
}
else
{
it->S = (it->S)+1;
}
}
int ans=0;
FORS(it,container)
if (it->S == 0)
ans++;
cout<<ans;
return 0;
}