Pagini recente » Cod sursa (job #1510382) | Cod sursa (job #3249925) | Cod sursa (job #2234010) | Cod sursa (job #2400957) | Cod sursa (job #2072115)
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
struct punct{
double x, y;
};
int N, S;
punct P[1500];
bool compara(punct A, punct B){
return A.x+A.y<B.x+B.y;
}
bool egale(double a, double b){
return fabs(a-b)<0.003;
}
double distanta(punct A, punct B){
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
bool gaseste(punct A, punct B, int i, double dist){
int j, m;
double dn, dm;
j=N-1;
while (i<=j){
m=(i+j)/2;
dn=distanta(A, P[m]); dm=distanta(B, P[m]);
if (egale(dn, dm) && egale(dn, dist))
return true;
if (dn<dist)
i=m+1;
else
j=m-1;
}
return false;
}
int main(){
int i, j;
ifstream fin ("triang.in");
fin >> N;
for (i=0; i<N; i++)
fin >> P[i].x >> P[i].y;
fin.close();
sort(P, P+N, compara);
for (i=0; i<N-2; i++)
for (j=0; j<N-1; j++)
if (gaseste(P[i], P[j], j+1, distanta(P[i], P[j])))
S++;
ofstream fout ("triang.out");
fout << S << '\n';
fout.close();
return 0;
}