图形化找最短两点

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
#include<graphics.h>
#include<conio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main() {
//画点
int x[30], y[30];
for (int i = 0; i < 30; i++) {
x[i] = rand() % (60 - 10 + 1) + 10;
y[i]= rand() % (60 - 10 + 1) + 10;
initgraph(500, 500);
setbkcolor(0);
putpixel(x[i], y[i], 30);
}
//画线
int L = 10000;
for (int i = 0; i < 30; i++) {
for (int j = 0; j < 30; i++) {
Line(x[i], y[i], x[j], y[j]);
int s = sqrt((x[i] * x[i] - x[j] * x[j]) + (y[i] * y[i] - y[j] * y[j]));
if (s < L&&s != 0)
L = s;
else
clearLine(x[i], y[i], x[j], y[j]);
}
}

getch();
closegraph();
}