PhieuLang

BT1

Sep 24th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<time.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5. using namespace std;
  6.  
  7. #define MAX 5000
  8. #define MAX2 20000
  9.  
  10. struct diem
  11. {
  12.     int x;
  13.     int y;
  14. };
  15. int main()
  16. {
  17.     diem S[MAX];
  18.     diem S2[MAX2];
  19.     srand(time(NULL));
  20.     for(int i=0;i<MAX;i++)
  21.     {
  22.         S[i].x = rand();
  23.         S[i].y = rand();
  24.     }
  25.     for(int i=0;i<MAX2;i++)
  26.     {
  27.         S2[i].x = rand();
  28.         S2[i].y = rand();
  29.     }
  30.     double kc;
  31.     double min;
  32.     diem dmin;
  33.     double tich;
  34.     double tich2;
  35.     double tich3;
  36.     double tich4;
  37.     double tich5;
  38.     double tich6;
  39.     double tong;
  40.     double tong2;
  41.     double tong3;
  42.     double tong4;
  43.     double abs1;
  44.     double sqrt1;
  45.  
  46.     for(int j=0;j<MAX;j++)
  47.     {
  48.         tich3    = S[j].x*S[0].x;
  49.         tich4    = S[j].y*S[0].y;
  50.         tich     = S[j].x*S2[0].y;
  51.         tich2    = S[j].y*S2[0].x;
  52.         tich5    = S2[0].x*S2[0].x;
  53.         tich6    = S2[0].y*S2[0].y;
  54.         tong     = tich + tich2;
  55.         tong2    = tich3+tich4;
  56.         tong3    = tich5+tich6;
  57.         tong4    = tong2+tong3;
  58.         abs1     = abs(tong);
  59.         sqrt1    = sqrt(tong4);
  60.         min = abs1/sqrt1;
  61.         dmin = S2[0];
  62.         tich3    = S[j].x*S[j].x;
  63.         tich4    = S[j].y*S[j].y;
  64.         for(int i=1;i<MAX2; i++)
  65.         {
  66.             //cout<<i<<endl;
  67.             tich     = S[j].x*S2[i].y;
  68.             tich2    = S[j].y*S2[i].x;
  69.             tich5    = S2[i].x*S2[i].x;
  70.             tich6    = S2[i].y*S2[i].y;
  71.             tong     = tich + tich2;
  72.             tong2    = tich3+tich4;
  73.             tong3    = tich5+tich6;
  74.             tong4    = tong2+tong3;
  75.             abs1     = abs(tong);
  76.             sqrt1    = sqrt(tong4);
  77.             kc     = abs1/sqrt1;
  78.             if(kc<min)
  79.             {
  80.               min=kc;
  81.               dmin=S2[i];
  82.             }
  83.         }
  84.         cout<<j<<"\tMin:"<<min<<"\tA.x:"<<S[j].x<<"\tA.y:"<<S[j].y<<"\tB.x:"<<dmin.x<<"\tB.y:"<<dmin.y<<endl;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment