Cod sursa(job #1072877)

Utilizator teodor98Teodor Sz teodor98 Data 5 ianuarie 2014 09:10:46
Problema Numarare triunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#include <algorithm>
#define N 801
int v[N],n,nr=0;
using namespace std;
ifstream in("nrtri.in");
ofstream out("nrtri.out");
bool is_triunghi(int a,int b,int c)
{
    return ((a<=b+c && b<=a+c && c<=a+b) && (a>0 && b>0 && c>0));
}

void subsir()
{
    int pas, c=0 ;
    sort(v+1, v+n+1);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
           c=j+1;
           pas = 1 <<10;
           while(pas!=0)
           {
               if(c+pas <=n && v[c+pas] <= v[i]+v[j])
                    c+=pas;
               pas/=2;
           }
           if(is_triunghi(v[i], v[j], v[c]))
                 nr++;


        }
}

void citire()
{
    in >> n;
    for(int i=1;i<=n;i++)
   {
       in >> v[i];

   }
}
int main()
{
    citire();
    subsir();

   // out << (is_triunghi(v[1],v[2],v[4])&&4<=n);
      out << nr;
    return 0;
}