Pagini recente » Cod sursa (job #168787) | Cod sursa (job #1351351) | Cod sursa (job #1016296) | Cod sursa (job #1379769) | Cod sursa (job #2123760)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("nrtri.in");
ofstream g("nrtri.out");
int n,i,j,v[805],st,dr,mij,nr;
int main()
{
f>>n;
for(i=1; i<=n; i++)
{
f>>v[i];
}
sort(v+1,v+n+1);
for(i=1; i<n-1; i++)
for(j=i+1; j<n; j++)
{
st=j+1;
dr=n;
while(st<=dr)
{
mij=(st+dr)/2;
if(v[mij]<=v[i]+v[j])
st=mij+1;
else
dr=mij-1;
}
if(v[dr]!=v[j])
{
if(v[dr]<=v[i]+v[j]&&v[dr]+v[i]>=v[j]&&v[j]+v[dr]>=v[i])
{
nr++;
}
}
}
g<<nr;
return 0;
}