Pagini recente » Cod sursa (job #1870673) | Monitorul de evaluare | Cod sursa (job #1845841) | Cod sursa (job #1996877) | Cod sursa (job #3351653)
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
struct Point {
int x, y;
};
const int INF = 100000;
const double eps = 1.e-14;
double dist(Point P1, Point P2) {
return ( sqrt( ( (P2.x - P1.x) * (P2.x - P1.x) ) + ( (P2.y - P1.y) * (P2.y - P1.y) ) ) );
}
bool SamePoint(Point P1, Point P2) {
if ( ( fabs(P1.x - P2.x) < eps ) && ( fabs(P1.y - P2.y) < eps ) ) {
return 1;
}
return 0;
}
Point median(Point P1, Point P2) {
Point M;
M.x = (P1.x + P2.x) / 2;
M.y = (P1.y + P2.y) / 2;
return M;
}
double slope(Point P1, Point P2) {
if (fabs(P2.x - P1.x) < eps)
return INF;
else
return ((P2.y - P1.y) / (P2.x - P1.x));
}
ifstream I("trapez.in");
ofstream O("trapez.out");
const int GMAN = 10005;
double pante[GMAN];
Point toyota[GMAN];
int main(){
int n, Ebony = 0, Ivory = 0, c = 0, tem = 1, r = 0;
I >> n;
for (int i = 0; i < n; i++) {
I >> toyota[i].x >> toyota[i].y;
}
while (true) {
if (Ivory == n) {
Ebony++;
Ivory = Ebony + 1;
if (Ebony >= n) break;
}
else {
Ivory++;
}
pante[c] = slope(toyota[Ebony], toyota[Ivory]);
c++;
}
sort(pante + 1, pante + c + 1);
for (int i = 0; i < c; i++) {
if (fabs(pante[i] - pante[i - 1]) < eps)
tem++;
else {
r = r + tem * (tem - 1) / 2;
r = 1;
}
}
O << r;
return 0;
}