Cod sursa(job #1571181)
| Utilizator | Data | 17 ianuarie 2016 14:11:57 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.02 kb |
#include <iostream>
#include <algorithm>
using namespace std;
int a[101];
int main()
{
int n;
int cnt = 0, poz, v, mij, ls, ld;
bool gasit;
cin >> n;
for ( int i = 1; i <= n; ++i)
cin >> a[i];
sort( a+1, a+1+n);
for ( int i = 3; i <= n; ++i)
{
for ( int j = 1; j <= n; ++j)
{
v = a[i] - a[j];
gasit = false;
mij = 0;
ls = j+1;
ld = i-1;
while ( !gasit && ls <= ld)
{
mij = (ls+ld)/2;
if ( v == a[mij])
{
poz = mij;
gasit = true;
}
else
if ( v > a[mij])
ls = mij+1;
else
ld = mij-1;
}
if ( gasit == true)
cnt++;
}
}
if ( cnt == 0)
cout << "NU";
else
cout <<cnt;
return 0;
}
