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

📄 dialog34.cpp

📁 本程序是一个最近邻分类算法的演示程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				  {
				        if(*(test+2*j)==x&&*(test+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(test+2*i)=x;
                        *(test+2*i+1)=y;i++;
				  }
			       
			}	 
	   }
		/////////////////////////////////////////////
		i=100;
        while(i<200)
	   {
           x=(int)(rand()%200);
			y=(int)(rand()%200);
			BOOL flag=false;
		    if((x-100)*(x-100)+(y-100)*(y-100)<10000)
			{
			      for(int j=100;j<i;j++)
				  {
				        if(*(test+2*j)==x&&*(test+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(test+2*i)=x;
                        *(test+2*i+1)=y; i++;
				  }
			      
			}	 
	   }
		/////////////////////////////////////////
		i=200;
         while(i<300)
	   {
           x=(int)(rand()%200)+int((r/2)*1.732);
			y=(int)(rand()%200);
			BOOL flag=false;
		    if((x-100-int((r/2)*1.732))*(x-100-int((r/2)*1.732))+(y-100)*(y-100)<10000)
			{
			      for(int j=200;j<i;j++)
				  {
				        if(*(test+2*j)==x&&*(test+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(test+2*i)=x;
                        *(test+2*i+1)=y; i++;
				  }
			      
			}	 
	   }
		 ///////////////////////////////////////just
         int count=0;
		  for(i=0;i<100;i++)
	{
      int c1,c2,c3;
	  int j=1;
	  int x1,x2,y1,y2;
	  x1=*(onep+0);x2=*(test+2*i);y1=*(onep+1);y2=*(test+2*i+1);
	  c1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<120;j++)
	  {
		  x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c1>temp)
			  {c1=temp;
			  }
	  }
	  x1=*(towp+0);x2=*(test+2*i);y1=*(towp+1);y2=*(test+2*i+1);
	  c2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<130;j++)
	  {
           x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c2>temp)
			  {c2=temp;
			  }
	  }
       x1=*(threep+0);x2=*(test+2*i);y1=*(threep+1);y2=*(test+2*i+1);
	  c3=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<150;j++)
	  {
            x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c3>temp)
			  {c3=temp;
			  }
	  }
	  if((c1>c2)||(c1>c3))count++;
	}
	int ty=0;
	/////////////////////////////////////////////////////////////////////////
	 for( i=100;i<200;i++)
	{
      int c1,c2,c3;
	  int j=1;
	  int x1,x2,y1,y2;
	  x1=*(onep+0);x2=*(test+2*i);y1=*(onep+1);y2=*(test+2*i+1);
	  c1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<120;j++)
	  {
		  x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c1>temp)
			  {c1=temp;
			  }
	  }
	  x1=*(towp+0);x2=*(test+2*i);y1=*(towp+1);y2=*(test+2*i+1);
	  c2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<130;j++)
	  {
           x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c2>temp)
			  {c2=temp;
			  }
	  }
       x1=*(threep+0);x2=*(test+2*i);y1=*(threep+1);y2=*(test+2*i+1);
	  c3=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<150;j++)
	  {
            x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c3>temp)
			  {c3=temp;
			  }
	  }
	  if((c1<c2)||(c2>c3))count++;
	}
	 //////////////////////////////////////////
	  ty=0;
     for( i=200;i<300;i++)
	{
       int c1,c2,c3;
	  int j=1;
	  int x1,x2,y1,y2;
	  x1=*(onep+0);x2=*(test+2*i);y1=*(onep+1);y2=*(test+2*i+1);
	  c1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<120;j++)
	  {
		  x1=*(onep+2*j);y1=*(onep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c1>temp)
			  {
				  c1=temp;
			  }
	  }
	  x1=*(towp+0);x2=*(test+2*i);y1=*(towp+1);y2=*(test+2*i+1);
	  c2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<130;j++)
	  {
           x1=*(towp+2*j);y1=*(towp+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c2>temp)
			  {c2=temp;
			  }
	  }
       x1=*(threep+0);x2=*(test+2*i);y1=*(threep+1);y2=*(test+2*i+1);
	  c3=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
	  for(j=1;j<150;j++)
	  {
            x1=*(threep+2*j);y1=*(threep+2*j+1);x2=*(test+2*i);y2=*(test+2*i+1);
		  int temp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
			  if(c3>temp)
			  {c3=temp;
			  }
	  }
     	  if((c1<c3)||(c2<c3))count++;
	}
     
     ct[i1]=((double)(300-count))/300;
		rt[i1]=((double)(0))/300;
		et[i1]=((double)(count))/300;
		double runtime;  
		QueryPerformanceCounter(&litmp);//获得终止值
    qt2=litmp.QuadPart;
    runtime=(double)(qt2-qt1)/dff;
		tt[i1]=runtime;
	CString tmp;
		  tmp.Format("%d",zt[i1]);
		  m_l.SetItemText (i1, 0, tmp);
          tmp.Format("%3.4f",ct[i1]);
          m_l.SetItemText (i1, 1, tmp);
          tmp.Format("%3.4f",rt[i1]);
          m_l.SetItemText (i1, 2, tmp);
         tmp.Format("%3.5f",runtime);
         m_l.SetItemText (i1, 4, tmp);
tmp.Format("%3.4f",et[i1]);
          m_l.SetItemText (i1, 3, tmp);
		  if(i1%2!=0)
		  {
			  m_l.flag[i1]=true;
		  }
         //////////////////////////////just
	}//for
  }//if
  if(m_b2.down)
  {
	  for(int i1=0;i1<20;i1++)
	  {
          	int x,y;
		LARGE_INTEGER litmp;
LONGLONG qt1,qt2;
double dff;
QueryPerformanceFrequency(&litmp);//获得时钟频率
dff=(double)litmp.QuadPart;
QueryPerformanceCounter(&litmp);//获得初始值
    qt1=litmp.QuadPart;
		int r=300-10*i1;
		zt[i1]=r;
	   int i=0;
       srand( (unsigned)time( NULL ) );
	   while(i<120)
	   {
           x=(int)(rand()%200);
			y=(int)(rand()%200)+100+r-100;
			BOOL flag=false;
		    if((x-100)*(x-100)+(y-100-r)*(y-100-r)<10000)
			{
			      for(int j=0;j<i;j++)
				  {
				        if(*(onep+2*j)==x&&*(onep+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(onep+2*i)=x;
                        *(onep+2*i+1)=y;i++;
				  }
			       
			}	 
	   }
//////////////////////////////////////////////////////////////////////////////
      i=0;
	   while(i<130)
	   {
           x=(int)(rand()%200);
			y=(int)(rand()%200);
			BOOL flag=false;
		    if((x-100)*(x-100)+(y-100)*(y-100)<10000)
			{
			      for(int j=0;j<i;j++)
				  {
				        if(*(towp+2*j)==x&&*(towp+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(towp+2*i)=x;
                        *(towp+2*i+1)=y;i++;
				  }
			       
			}	 
	   }
	   ///////////////////////////////
	   i=0;
        while(i<150)
	   {
           x=(int)(rand()%200)+int((r/2)*1.732);
			y=(int)(rand()%200);
			BOOL flag=false;
		    if((x-100-int((r/2)*1.732))*(x-100-int((r/2)*1.732))+(y-100)*(y-100)<10000)
			{
			      for(int j=0;j<i;j++)
				  {
				        if(*(threep+2*j)==x&&*(threep+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(threep+2*i)=x;
                        *(threep+2*i+1)=y;i++;
				  }
			       
			}	 
	   }
////////////////////////////////////////////////////////////
        i=0;
        while(i<100)
	   {
           x=(int)(rand()%200);
			y=(int)(rand()%200)+100+r-100;
			BOOL flag=false;
		    if((x-100)*(x-100)+(y-100-r)*(y-100-r)<10000)
			{
			      for(int j=0;j<i;j++)
				  {
				        if(*(test+2*j)==x&&*(test+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(test+2*i)=x;
                        *(test+2*i+1)=y;i++;
				  }
			       
			}	 
	   }
		/////////////////////////////////////////////
		i=100;
        while(i<200)
	   {
           x=(int)(rand()%200);
			y=(int)(rand()%200);
			BOOL flag=false;
		    if((x-100)*(x-100)+(y-100)*(y-100)<10000)
			{
			      for(int j=100;j<i;j++)
				  {
				        if(*(test+2*j)==x&&*(test+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(test+2*i)=x;
                        *(test+2*i+1)=y;i++;
				  }
			       
			}	 
	   }
		/////////////////////////////////////////
		i=200;
         while(i<300)
	   {
           x=(int)(rand()%200)+int((r/2)*1.732);
			y=(int)(rand()%200);
			BOOL flag=false;
		    if((x-100-int((r/2)*1.732))*(x-100-int((r/2)*1.732))+(y-100)*(y-100)<10000)
			{
			      for(int j=200;j<i;j++)
				  {
				        if(*(test+2*j)==x&&*(test+2*j+1)==y)
						{
					       flag=true;
					      j=i;
						}
				  }
			      if(!flag)
				  {
                      *(test+2*i)=x;
                        *(test+2*i+1)=y;i++;
				  }
			       
			}	 
	   }
		 ///////////////////////////////////////just
		  
          int k=38;
		i=0;int count=0;
		////////////////////////////////////
		for(i=0;i<100;i++)
		{
            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*i);y2=*(test+2*i+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*i);y2=*(test+2*i+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*i);y2=*(test+2*i+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(i=100;i<200;i++)
		{
            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*i);y2=*(test+2*i+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*i);y2=*(test+2*i+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*i);y2=*(test+2*i+1);

⌨️ 快捷键说明

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