拟合

来源:互联网 发布:建材软件价格 编辑:程序博客网 时间:2024/04/30 11:03

#include "stdio.h"
#include "math.h"

#define len_arr 60
#define T 100//门限值的平方

void main()
{
 int a[len_arr];
 int g[20];
 int q;
// int s;
 a[len_arr]="950 950 952 953 953 951 950 950 953 964 982 1007 1034 1071 1104 1142 1179 1207 1229 1244 1256 1260 1242 1216 1189 1166 1139 1106 1075 1053 1043 1025 1003 985 975 967 959 949 938 930 925 923 920 914 912 914 916 920 916 916 914 915 918 921 918 918 917 915 919 921 922 919 917 920 922 923 922 919 917 917 921 922 921 920 918 915 917 919 921 918 917 918 921 920 918 919 921 920 925 928 926 927 925 930 930 934 935 938 937 940 944 949 950 952 954 958 964 972 974 976 977 978 982 983 988 989 987 990 991 992 993 990 990 989 989 987 987 985 984 981 980 981 978 971 968 971 972 971 973 968 962 963 966 967 964 967 966 966 966 965 965 962 962 962 961 961 961 959 958 959 ";
 /*
 int a[10];
 for(s=0;s<10;s++)
 {
  a[s]=s;
 }
*/
 g[20]=fitt(a);
 for(q=0;q<20;q++)
 {
  printf("%d",g[q]);
 }
 printf("/n");
}

int fitt(int *a[])
{
 int i=0;//起点时间坐标
 int j=2;//终点时间坐标
 int r;//i,j间任一点的时间坐标
 int l;//线段AB的长度的平方
 int lac[20];//记录线段起点坐标;8~12段线段即可表示
 int p;//lac数组哨兵
 int b,c,d,e;//辅助边长的平方
 int dist[len_arr];//a[r]的垂线段的长度的平方
 

 for(;j<=len_arr;j++)
 {
  lac[p++]=i;//上一线段的终点就是下一线段的起点,所以只需记录起点坐标
  l=(j-i)^2+(a[j]-a[i])^2;
  r=i+1;//AB间的点的时间坐标,从i+1到j-1
  for(;r<j-1;)
  {
   if(a[r]>a[i])
   {
    b=pow((r-i),2)+pow((a[r]-a[i]),2);
   }
   else
   {
    b=pow((r-i),2)+pow((a[i]-a[r]),2);
   }
   
   if(a[j]>a[r])
   {
    c=pow((j-r),2)+pow((a[j]-a[r]),2);
   }
   else
   {
    c=pow((j-r),2)+pow((a[r]-a[j]),2);
   }

   e=pow((sqrt(l)-sqrt(d)),2);//sqrt(e)+sqrt(d)=l
   b=c-e+d;
   dist[r]=b-d;

   if(dist[r]<T)
   {
    r++;
   }
   else
   {
    i=j-1;
    j=j+1;
   }
  }

 }
 return lac;
}

 

没有语法错误,但是一运行就死机。