蛮力法求凸包问题

蛮力法求凸包问题
#include
#include

#define MAX 100

struct point
{
double x;
double y;
};
struct point p[MAX]; // The given points
int pnum; // The number of the given points
int idex[MAX]; // The indexes of points of convex-hull
int inum = 0; // The number of the indexes

void input()
{
int i, j;
//fp = fopen(".\closest_pair.txt", “r”);
scanf("%d", &pnum); // First line is the number of points
// The following lines are the points
for (i = 0; i < pnum; i++)
scanf("%lf %lf", &p[i].x, &p[i].y);
printf(“There are %d points:\n”, pnum);
for (j = 0; j < pnum; j++)
printf("%.0lf,%.0lf\n", p[j].x, p[j].y);
}
void output()
{
int i,n;
printf(“The convex-hull is\n”);
for (i = 0;i< pnum; i++)
if(idex[i]==2) {
printf("(%.0lf,%.0lf)\n", p[i].x, p[i].y);
n=i;
idex[i]=0;
break;}
for (i = 0;i< pnum; i++)
if(idex[i]==1) {
printf("(%.0lf,%.0lf)\n", p[i].x, p[i].y);}
for (i = 0;i< pnum; i++)
if(idex[i]==2) {
printf("(%.0lf,%.0lf)\n", p[i].x, p[i].y);}

}

void process()
{
float a,b,c;
int j,k,i;
for(j=0;j for(i=j+1;i a=p[j].y-p[i].y;
b=p[i].x-p[j].x;
c=p[i].xp[j].y-p[i].yp[j].x;
int sign1=0;
int sign2=0;
for(k=0;k if( kj||ki )
continue;
if((ap[k].x+bp[k].y)c) {
sign1++;
sign2++;
}
if((ap[k].x+bp[k].y) sign1++;
}
if((ap[k].x+bp[k].y)>c) {
sign2++;
}
}
if(sign1
(pnum-2)||sign2==(pnum-2)) {
idex[j]=2;
idex[i]=1;
}
sign1=0;
sign2=0;
}}}

int main()
{

input();
process();
output();
return 0;

}

//另外欢迎访问个人电脑壁纸分享网站www.shiguang73.com各种精美壁纸

你可能感兴趣的:(蛮力法求凸包问题)