图形化找最短两点 Posted on 2017-09-13 | 12345678910111213141516171819202122232425262728293031#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();}