Pagini recente » Cod sursa (job #2346881) | Cod sursa (job #2696623) | Cod sursa (job #2809360) | Cod sursa (job #2943010) | Cod sursa (job #441077)
Cod sursa(job #441077)
#include <cstdio>
#include <vector>
#include <algorithm>
struct point {
long x,y;
};
struct slope {
long long x1,x2,y1,y2;
double slope;
};
bool test(slope a, slope b) {
if (a.x2-a.x1 == 0 && b.x2-b.x1 == 0) return false;
if (a.x2-a.x1 == 0) return (-31220<(b.y2-b.y1)/(b.x2-b.x1));
else if (b.x2-b.x1 == 0) return ((a.y2-a.y1)/(a.x2-a.x1)<-31220);
else
return ((a.y2-a.y1)/(a.x2-a.x1)<(b.y2-b.y1)/(b.x2-b.x1));
}
int main() {
FILE *f,*g;
f = fopen("trapez.in","r");
g = fopen("trapez.out","w");
int n;
fscanf(f,"%d\n",&n);
point a[n+1];
for(int i=0; i<n; i++) {
fscanf(f,"%d %d\n",&a[i].x,&a[i].y);
}
std::vector<slope> b;
slope aux;
int rez = 0;
for(int i=0; i<n-1; i++) {
for(int j=i+1; j<n; j++) {
//if (a[i].x==a[j].x) { rez++; continue; }
aux.x1 = a[i].x;
aux.x2 = a[j].x;
aux.y1 = a[i].y;
aux.y2 = a[j].y;
//if (a[j].x-a[i].x==0) aux.slope = -32117;
//else aux.slope = (double)((a[j].y-a[i].y)*1000)/((a[j].x-a[i].x)*1000);
b.push_back(aux);
}
}
sort(b.begin(), b.end(), test);
for(int i=1; i!=n;i++) {
if (test(b[i-1],b[i])) {
rez++;
i = i+2;
}
}
fprintf(g,"%d",rez);
fclose(f);
fclose(g);
}