15.12.2010, 17:34. Просмотров 348. Ответов 0
Дано Зп точек на плоскости, причем никакие три из них не лежат на одной пря¬мой. Построить множество п треугольников с вершинами в этих точках так, что¬бы никакие два треугольника не пересекались и не содержали друг друга
вот есть программа , как ее переделать
C++ |
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
79
80
81
82
83
84
85
86
87
88
89
90
| #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct point {
int x;
int y;
point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
point& operator = (const point& p) {
x = p.x;
y = p.y;
return *this;
}
bool operator < (const point& p) {
if(x < p.x)
return true;
if(x == p.x && y < p.y)
return true;
return false;
}
};
struct triangle {
point points[3];
};
int main(int argc, char *argv[]) {
int n;
cout << "Input a triangles number:" << endl;
cin >> n;
vector<point> points;
n = n*3;
int i=0;
for(; i<n; i++) {
point p;
cout << "Input point[" << i << "] x:" << endl;
cin >> p.x;
cout << "Input point[" << i << "] y:" << endl;
cin >> p.y;
points.push_back(p);
}
sort(points.begin(), points.end());
vector<triangle> triangles;
for(i=0; i<n; i++) {
triangle t;
t.points[0] = points[i++];
t.points[1] = points[i++];
t.points[2] = points[i];
triangles.push_back(t);
}
cout << "Triangles:" << endl;
vector<triangle>::iterator iter;
for(iter = triangles.begin(); iter != triangles.end(); ++iter)
cout << "(" <<
"(" << iter->points[0].x << ", " << iter->points[0].y << "), "
"(" << iter->points[1].x << ", " << iter->points[1].y << "), "
"(" << iter->points[2].x << ", " << iter->points[2].y << "))" << endl;
system("Pause");
return 0;
} |
|