Pagini recente » Atasamentele paginii Clasament eusebiuoji2005cls9 | Istoria paginii utilizator/corinatud | Istoria paginii runda/simulare-cartita-24 | Cod sursa (job #1369665) | Cod sursa (job #1844310)
#include <stdio.h>
#include <stdlib.h>
double getSlope(int x1, int x2, int y1, int y2){
if(x2 == x1){
return 1.005;
}
double slope = (double)(y2 - y1)/(x2 - x1);
return slope;
}
int cmpfunc (const void * a, const void * b)
{
return ( *(double*)a - *(double*)b );
}
void sortArray(double *v, int k){
double temp;
for(int i = 0; i < k - 1; i++){
for(int j = i + 1; j < k; j++){
if(v[i] > v[j]){
temp = v[i];
v[i] = v[j];
v[j] = temp;
}
}
}
}
void quick_sort(double *arr, int low, int high)
{
int pivot,j,temp,i;
if(low < high)
{
pivot = low;
i = low;
j = high;
while(i<j)
{
while((arr[i]<=arr[pivot])&&(i<high))
{
i++;
}
while(arr[j]>arr[pivot])
{
j--;
}
if(i<j)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
temp=arr[pivot];
arr[pivot]=arr[j];
arr[j]=temp;
quick_sort(arr,low,j-1);
quick_sort(arr,j+1,high);
}
}
int getResult(double *v, int k){
double val = v[0] - 1;
int total = 0;
for(int i = 0; i < k; i++){
if(v[i] == val){
total++;
}
else{
val = v[i];
}
}
return total;
}
int main(){
FILE *in, *out;
int N, k = 0;
int arr_x[1000], arr_y[1000];
double slopes[500500];
in = fopen("trapez.in", "r");
out = fopen("trapez.out", "w");
fscanf(in, "%d", &N);
if(N < 4){
fprintf(out, "%d\n", 0);
return 0;
}
for( int i = 0; i < N; i++){
fscanf(in, "%d", &arr_x[i]);
fscanf(in, "%d", &arr_y[i]);
}
for(int i = 0; i < N - 1; i++){
for(int j = i + 1; j < N; j++){
slopes[k++] = getSlope(arr_x[i], arr_x[j], arr_y[i], arr_y[j]);
}
}
qsort(slopes, k, sizeof(double), cmpfunc);
fprintf(out, "%d\n", getResult(slopes, k));
return 0;
}