Question Name:Counting Triangles

#include<iostream>
#include<bits/stdc++.h>
#include<map>
using namespace std;
main()
{
long long n,count=0;
cin>>n;
array<long long , 3> val;
map<array<long long , 3>,long long> cnt;
while(n--)
{
cin>>val[0]>>val[1]>>val[2];
sort(val.begin(),val.end());
cnt[val]++;
}
for(auto i=cnt.begin();i!=cnt.end();++i)
{
if(i->second==1)
count++;
}
cout<<count<<endl;
}
  • Problem Description
    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.

    Note : It is always possible to form triangle with given sides.

    INPUT:

    First line contains n, the number of triangles. Each of next n lines contain three integers a,b,c (sides of a triangle).

    Output:

    print single integer, the number of unique triangles.

    Constraints:

    1 <= n <= 10^5
    1 <= a,b,c <= 10^15
  • Test Case 1
    Input (stdin)3
    1 2 3
    2 3 4
    2 4 3
    Expected Output1
  • Test Case 2
    Input (stdin)5
    7 6 5
    5 7 6
    8 2 9
    2 3 4
    2 4 3
    Expected Output1
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO