-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharea1.cpp
78 lines (69 loc) · 1.75 KB
/
area1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <math.h>
using namespace std;
double tarea(double s1, double s2, double s3);
bool search(double a[], int len, double item);
int main()
{
int t;
cin >> t;
int n, tmp;
const int N = 50;
int coord[N];
double areas[1225]; int k = 0;
int ans[100]; int g = 0;
double a, b, c, ar;
for (int i = 0; i < t; i++)
{
int n1 = 0;
cin >> n;
k = 0;
// max no. of areas possible = Nc2 = 50c2 = 1225
// to get single-line input for array
while( n1 < n && scanf( "%d", &tmp) != EOF)
{
coord[n1++] = tmp;
}
for (int x1 = 0; x1 < n; x1++)
{
for (int x2 = x1 + 1; x2 < n; x2++)
{
a = sqrt(1 + (coord[x1] * coord[x1]));
b = sqrt(1 + (coord[x2] * coord[x2]));
c = coord[x2] - coord[x1];
ar = tarea(a, b, c);
bool search_result = search(areas, k, ar);
if (search_result == false && ar != 0)
{
areas[k++] = (double)ar;
}
}
}
ans[g++] = k;
}
for(int i = 0; i < g; i++)
{
cout << ans[i] << endl;
}
return 0;
}
double tarea(double s1, double s2, double s3)
{
double s = (s1 + s2 + s3) / 2;
double a = sqrt(s * (s - s1) * (s - s2) * (s - s3));
return a;
}
bool search(double a[], int len, double item)
{
bool flag = false;
for (int i = 0; i < len; i++)
{
if (abs(a[i] - item) < 0.001)
{
flag = true;break;
}
}
return flag;
}