wawmnysys 2016-03-03 06:25 采纳率: 0%
浏览 1183
已结题

凸包问题,但是不知道哪里出错了

代码部分:
#include
#include
#include
#include
using namespace std;
#define MaxNode 1000
int stack[MaxNode];
int top;
struct POINT
{
int x;
int y;
};
struct POINT point[MaxNode];
void swap(struct POINT point[], int m, int n){//点之间的数据交换
struct POINT temp;
temp = point[m];
point[m] = point[n];
point[n] = temp;

}
double multi(struct POINT p1, struct POINT p2, struct POINT p0){//叉乘,p1点是转折点
return (p2.x - p1.x)*(p0.y - p1.y) - (p2.y - p1.y)*(p0.x - p1.x);
}
double distance(struct POINT p1, struct POINT p2){//两点之间的距离
return((p1.x - p2.x) ^ 2 + (p1.y - p2.y) ^ 2) ^ (1 / 2);
}
int cmp(const void *a, const void *b)
{
struct POINT *c = (struct POINT *)a;
struct POINT *d = (struct POINT *)b;
double k = multi(*c, *d, point[0]);
if (k else if (k == 0 && distance(*c, point[0]) >= distance(*d, point[0])) return 1; //极角相同,比距离
else return -1;
}
double jijiao(POINT p1, POINT p0){
return(p1.y - p0.y) / (p1.x - p0.x);
}
void gscan(int n){
for (int i = 0; i < n; i++){//找到P0基础点
int u = 0;
if ((point[i].y < point[u].y) || (point[i].y == point[u].y&&point[i].x < point[u].x))
u = i;
swap(point, 0, u);
}
qsort(point + 1, n - 1, sizeof(point[0]), cmp);//将剩余的点以极角由小到大排序
for (int r = 0; r < 3; r++)
stack[r] = r;
top = 2;
for (int k = 3; k < n; k++){
while (multi(point[top], point[k], point[top - 1]) >0){
if (top == 0)break;
top--;
}
top++;
stack[top] = k;
}
}
int main(){
int n;
cin >> n;
struct POINT point;
for (int i = 0; i < 3; i++){
cin >> &point[i].x >> &point[i].y;
}
gscan(n);
for (int w = 0; w < n; w++){
cout << stack[w] << endl;
}
}
报错有三十多个,但是大部分都是点开是这样的typedef typename _Iter::difference_type difference_type;点开错误之后,到另一个新开的代码界面。

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-03-06 04:17
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序