"Find out the distance in the plane of your nearest enemy" without calculating the distance

Source: Internet
Author: User

  #include  <iostream>using namespace std;//own coordinates   enemy coordinates (A, b) double a[6]={ 0,1,2,3,4,5};d ouble b[6]={0,1,2,3,4,5};d ouble c[6]={999};int who=0;void fun () {     for (int i=1;i<6;i++)      {          a[i]-=a[0];b[i]-=b[0];     }     for (int  i=1;i<6;i++)      {       c[i]=a[i]*a[i]+b [I]*b[i];     }     for (int i=1;i<6;i++)       {        if (c[i]<c[0])  {c[0]=c[i];who=i;}      }     cout<<who<<endl;} n Multiple points of optimization void fun () {    for (int i=1;i<6;i++)      {          //all mappings to the first region          a[i]-=a[0];b[i]-=b[0];          if (a[i]<0) a[i]*=-1;          if (b[i]<0) b[i]*=-1;     }           for (int i=1;i<6;i++)      {          //all mappings to First 1/2         if (A[i]<b[i]) Swap (a[i],b[i]);      }      for (int i=1;i<6;i++ )      {         //Find the smallest x,           if (a[i]<=a[1]) whos=i;     }       for (int i=1;i<6;i++)      {          //x with   Take the          if with the largest Y value (a[i]==a[whos]&&b[i]>= B[whos]) Whos=i;     }     cout<<who<<endl;} Int main () {cout <<  "hello,c++ world of anycodex!"  << endl;fun (); return 0;}

Stay in communication

"Find out the distance in the plane of your nearest enemy" without calculating the distance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.