-
Notifications
You must be signed in to change notification settings - Fork 0
/
exam2.c
84 lines (74 loc) · 2.97 KB
/
exam2.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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct Point
{
int x;
int y;
}Point;
float point_dist(struct Point p1, struct Point p2)
{
double dist=0;
dist = sqrt((double)((p1.x - p2.x)*(p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y)));
return dist;
}
int main()
{
struct Point five_point[5];
struct Point O_point;
O_point.x=0;
O_point.y=0;
scanf("%d %d",&five_point[0].x,&five_point[0].y);
scanf("%d %d",&five_point[1].x,&five_point[1].y);
scanf("%d %d",&five_point[2].x,&five_point[2].y);
scanf("%d %d",&five_point[3].x,&five_point[3].y);
scanf("%d %d",&five_point[4].x,&five_point[4].y);
int order[120][5]={
{0,1,2,3,4},{0,1,2,4,3},{0,1,3,2,4},{0,1,3,4,2},{0,1,4,2,3},{0,1,4,3,2},
{0,2,1,3,4},{0,2,1,4,3},{0,2,3,1,4},{0,2,3,4,1},{0,2,4,1,3},{0,2,4,3,1},
{0,3,1,2,4},{0,3,1,4,2},{0,3,2,1,4},{0,3,2,4,1},{0,3,4,2,1},{0,3,4,1,2},
{0,4,1,2,3},{0,4,1,3,2},{0,4,2,1,3},{0,4,2,3,1},{0,4,3,1,2},{0,4,3,2,1},
{1,0,2,3,4},{1,0,2,4,3},{1,0,3,2,4},{1,0,3,4,2},{1,0,4,2,3},{1,0,4,3,2},
{1,2,0,3,4},{1,2,0,4,3},{1,2,3,0,4},{1,2,3,4,0},{1,2,4,0,3},{1,2,4,3,0},
{1,3,0,2,4},{1,3,0,4,2},{1,3,2,0,4},{1,3,2,4,0},{1,3,4,2,0},{1,3,4,0,2},
{1,4,0,2,3},{1,4,0,3,2},{1,4,2,0,3},{1,4,2,3,0},{1,4,3,0,2},{1,4,3,2,0},
{2,1,0,3,4},{2,1,0,4,3},{2,1,3,0,4},{2,1,3,4,0},{2,1,4,0,3},{2,1,4,3,0},
{2,0,1,3,4},{2,0,1,4,3},{2,0,3,1,4},{2,0,3,4,1},{2,0,4,1,3},{2,0,4,3,1},
{2,3,1,0,4},{2,3,1,4,0},{2,3,0,1,4},{2,3,0,4,1},{2,3,4,0,1},{2,3,4,1,0},
{2,4,1,0,3},{2,4,1,3,0},{2,4,0,1,3},{2,4,0,3,1},{2,4,3,1,0},{2,4,3,0,1},
{3,1,0,2,4},{3,1,0,4,2},{3,1,2,0,4},{3,1,2,4,0},{3,1,4,0,2},{3,1,4,2,0},
{3,0,1,2,4},{3,0,1,4,2},{3,0,2,1,4},{3,0,2,4,1},{3,0,4,1,2},{3,0,4,2,1},
{3,2,1,0,4},{3,2,1,4,0},{3,2,0,1,4},{3,2,0,4,1},{3,2,4,0,1},{3,2,4,1,0},
{3,4,1,0,2},{3,4,1,2,0},{3,4,0,1,2},{3,4,0,2,1},{3,4,2,1,0},{3,4,2,0,1},
{4,1,0,2,3},{4,1,0,3,2},{4,1,2,0,3},{4,1,2,3,0},{4,1,3,0,2},{4,1,3,2,0},
{4,0,1,2,3},{4,0,1,3,2},{4,0,2,1,3},{4,0,2,3,1},{4,0,3,1,2},{4,0,3,2,1},
{4,2,1,0,3},{4,2,1,3,0},{4,2,0,1,3},{4,2,0,3,1},{4,2,3,0,1},{4,2,3,1,0},
{4,3,1,0,2},{4,3,1,2,0},{4,3,0,1,2},{4,3,0,2,1},{4,3,2,1,0},{4,3,2,0,1}
};
float dist[6]={0};
int best_dist=65535;
for(int i=0;i<120;i++)
{
int *one_order = order[i];
dist[0] = point_dist(O_point,five_point[one_order[0]]);
dist[1] = point_dist(five_point[one_order[0]],five_point[one_order[1]]);
dist[2] = point_dist(five_point[one_order[1]],five_point[one_order[2]]);
dist[3] = point_dist(five_point[one_order[2]],five_point[one_order[3]]);
dist[4] = point_dist(five_point[one_order[3]],five_point[one_order[4]]);
dist[5] = point_dist(five_point[one_order[4]],O_point);
float temp_dist=dist[0]+dist[1]+dist[2]+dist[3]+dist[4]+dist[5];
if(i==0)
best_dist = (int)temp_dist;
else
{
if(temp_dist<best_dist)
best_dist = (int)temp_dist;
else
{
best_dist = best_dist;
}
}
}
printf("%d\n",best_dist);
return 0;
}