⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogs1.cpp

📁 本程序是一个最近邻分类算法的演示程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	int i;
	for(i=0;i<20;i++)
	{
		res[i]=20+20*i;
	}
	for(i=0;i<450;i++)
	{
       zt[i]=0.0;
	}
	for(i=0;i<re;i++)
	{
     //////////////////////////////////////
          	//////////////////////////////////
	LARGE_INTEGER litmp;
LONGLONG qt1,qt2;
double dff;
QueryPerformanceFrequency(&litmp);//获得时钟频率
dff=(double)litmp.QuadPart;
QueryPerformanceCounter(&litmp);//获得初始值
    qt1=litmp.QuadPart;


		int k=res[i];
		int i1=0;int count=0;
		////////////////////////////////////
		for(i1=0;i1<100;i1++)
		{
            int l;
			int c1[120];
          int c2[130];
		  int c3[150];
		  int j=0;
		  for(j=0;j<120;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c1+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
		  for(l=0;l<k;l++)
		  {
			  for(j=119;j>l;j--)
			  {
				  if(c1[j]<c1[j-1])
				  {
					  int temp=c1[j-1];
					  c1[j-1]=c1[j];
					  c1[j]=temp;
				  }
			  }
		  }
          for(j=0;j<130;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c2+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
          for(l=0;l<k;l++)
		  {
			  for(j=129;j>l;j--)
			  {
				  if(c2[j]<c2[j-1])
				  {
					  int temp=c2[j-1];
					  c2[j-1]=c2[j];
					  c2[j]=temp;
				  }
			  }
		  }
          for(j=0;j<150;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c3+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
          for(l=0;l<k;l++)
		  {
			  for(j=149;j>l;j--)
			  {
				  if(c3[j]<c3[j-1])
				  {
					  int temp=c3[j-1];
					  c3[j-1]=c3[j];
					  c3[j]=temp;
				  }
			  }
		  }
		  int r1=0,r2=0,r3=0;
		  for(int h=0;h<k;h++)
		  {
             if(h<120)
			 {
			  if(c1[r1]<c2[r2]&&c1[r1]<c3[r3])
			  {
				 r1++;
			  }
              if(c2[r2]<c1[r1]&&c2[r2]<c3[r3])
			  {
				 r2++;
			  }
              if(c3[r3]<c1[r1]&&c2[r2]>c3[r3])
			  {
				 r3++;
			  }
			 }
			 else
			 {
                if(h<130)
				{
                   if(c2[r2]<c3[r3])
				   {
				       r2++;
				   }
                  if(c2[r2]>c3[r3])
				  {
				       r3++;
				  } 
				}
				else
					r3++;
			 }
		  }
		  if(r1<r2||r1<r3)count++;
		}
		int tt3=0;
		/////////////////////////////////
		 for(i1=100;i1<200;i1++)
		{
            int l;
			int c1[120];
          int c2[130];
		  int c3[150];
		  int j=0;
		  for(j=0;j<120;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c1+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
		  for(l=0;l<k;l++)
		  {
			  for(j=119;j>l;j--)
			  {
				  if(c1[j]<c1[j-1])
				  {
					  int temp=c1[j-1];
					  c1[j-1]=c1[j];
					  c1[j]=temp;
				  }
			  }
		  }
          for(j=0;j<130;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c2+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
          for(l=0;l<k;l++)
		  {
			  for(j=129;j>l;j--)
			  {
				  if(c2[j]<c2[j-1])
				  {
					  int temp=c2[j-1];
					  c2[j-1]=c2[j];
					  c2[j]=temp;
				  }
			  }
		  }
         for(j=0;j<150;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c3+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
          for(l=0;l<k;l++)
		  {
			  for(j=149;j>l;j--)
			  {
				  if(c3[j]<c3[j-1])
				  {
					  int temp=c3[j-1];
					  c3[j-1]=c3[j];
					  c3[j]=temp;
				  }
			  }
		  }
		  int r1=0,r2=0,r3=0;
		  for(int h=0;h<k;h++)
		  {
             if(h<120)
			 {
			  if(c1[r1]<c2[r2]&&c1[r1]<c3[r3])
			  {
				 r1++;
			  }
              if(c2[r2]<c1[r1]&&c2[r2]<c3[r3])
			  {
				 r2++;
			  }
              if(c3[r3]<c1[r1]&&c2[r2]>c3[r3])
			  {
				 r3++;
			  }
			 }
			 else
			 {
                if(h<130)
				{
                   if(c2[r2]<c3[r3])
				   {
				       r2++;
				   }
                  if(c2[r2]>c3[r3])
				  {
				       r3++;
				  } 
				}
				else
					r3++;
			 }
		  }
		  if(r2<r1||r2<r3)count++;
		}
		/////////////////////////////////
		 int tt5=0;
         for(i1=200;i1<300;i1++)
		{
            int l;
			int c1[120];
          int c2[130];
		  int c3[150];
		  int j=0;
		  for(j=0;j<120;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c1+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
		  for(l=0;l<k;l++)
		  {
			  for(j=119;j>l;j--)
			  {
				  if(c1[j]<c1[j-1])
				  {
					  int temp=c1[j-1];
					  c1[j-1]=c1[j];
					  c1[j]=temp;
				  }
			  }
		  }
         for(j=0;j<130;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c2+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
          for(l=0;l<k;l++)
		  {
			  for(j=129;j>l;j--)
			  {
				  if(c2[j]<c2[j-1])
				  {
					  int temp=c2[j-1];
					  c2[j-1]=c2[j];
					  c2[j]=temp;
				  }
			  }
		  }
          for(j=0;j<150;j++)
		  {
			  int x1,x2,y1,y2;
               x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i1);y2=*(test+2*i1+1);
		      *(c3+j)=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		  }
          for(l=0;l<k;l++)
		  {
			  for(j=149;j>l;j--)
			  {
				  if(c3[j]<c3[j-1])
				  {
					  int temp=c3[j-1];
					  c3[j-1]=c3[j];
					  c3[j]=temp;
				  }
			  }
		  }
		  int r1=0,r2=0,r3=0;
		  for(int h=0;h<k;h++)
		  {
             if(h<120)
			 {
			  if(c1[r1]<c2[r2]&&c1[r1]<c3[r3])
			  {
				 r1++;
			  }
              if(c2[r2]<c1[r1]&&c2[r2]<c3[r3])
			  {
				 r2++;
			  }
              if(c3[r3]<c1[r1]&&c2[r2]>c3[r3])
			  {
				 r3++;
			  }
			 }
			 else
			 {
                if(h<130)
				{
                   if(c2[r2]<c3[r3])
				   {
				       r2++;
				   }
                  if(c2[r2]>c3[r3])
				  {
				       r3++;
				  } 
				}
				else
					r3++;
			 }
		  }
		}
	///////////////////////////////////////
        zt[k-1]=(300.0-count)/300;
        double runtime;  
		QueryPerformanceCounter(&litmp);//获得终止值
    qt2=litmp.QuadPart;
    runtime=(double)(qt2-qt1)/dff;
ztm[i]=runtime;

		CString tmp;
		  tmp.Format("%d",k);
		  m_2.SetItemText (i, 0, tmp);
          tmp.Format("%3.4f",zt[k-1]);
          m_2.SetItemText (i, 1, tmp);
          tmp.Format("%3.4f",1-zt[k-1]);
          m_2.SetItemText (i, 2, tmp);
         tmp.Format("%3.5f",runtime);
          m_2.SetItemText (i, 3, tmp);
if(i&2!=0)
		 {
             m_2.flag[i]=true;
		 }

	}
	f1=true;
	CRect rectldj;   
	GetDlgItem(IDC_STATIC1)->GetWindowRect(rectldj);ScreenToClient(rectldj);
    InvalidateRect(rectldj,true);
GetDlgItem(IDC_STATIC3)->GetWindowRect(rectldj);ScreenToClient(rectldj);
    InvalidateRect(rectldj,true);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -