Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<time.h>
- #include<stdlib.h>
- #include<math.h>
- using namespace std;
- #define MAX 5000
- #define MAX2 20000
- struct diem
- {
- int x;
- int y;
- };
- int main()
- {
- diem S[MAX];
- diem S2[MAX2];
- srand(time(NULL));
- for(int i=0;i<MAX;i++)
- {
- S[i].x = rand();
- S[i].y = rand();
- }
- for(int i=0;i<MAX2;i++)
- {
- S2[i].x = rand();
- S2[i].y = rand();
- }
- double kc;
- double min;
- diem dmin;
- double tich;
- double tich2;
- double tich3;
- double tich4;
- double tich5;
- double tich6;
- double tong;
- double tong2;
- double tong3;
- double tong4;
- double abs1;
- double sqrt1;
- for(int j=0;j<MAX;j++)
- {
- tich3 = S[j].x*S[0].x;
- tich4 = S[j].y*S[0].y;
- tich = S[j].x*S2[0].y;
- tich2 = S[j].y*S2[0].x;
- tich5 = S2[0].x*S2[0].x;
- tich6 = S2[0].y*S2[0].y;
- tong = tich + tich2;
- tong2 = tich3+tich4;
- tong3 = tich5+tich6;
- tong4 = tong2+tong3;
- abs1 = abs(tong);
- sqrt1 = sqrt(tong4);
- min = abs1/sqrt1;
- dmin = S2[0];
- tich3 = S[j].x*S[j].x;
- tich4 = S[j].y*S[j].y;
- for(int i=1;i<MAX2; i++)
- {
- //cout<<i<<endl;
- tich = S[j].x*S2[i].y;
- tich2 = S[j].y*S2[i].x;
- tich5 = S2[i].x*S2[i].x;
- tich6 = S2[i].y*S2[i].y;
- tong = tich + tich2;
- tong2 = tich3+tich4;
- tong3 = tich5+tich6;
- tong4 = tong2+tong3;
- abs1 = abs(tong);
- sqrt1 = sqrt(tong4);
- kc = abs1/sqrt1;
- if(kc<min)
- {
- min=kc;
- dmin=S2[i];
- }
- }
- cout<<j<<"\tMin:"<<min<<"\tA.x:"<<S[j].x<<"\tA.y:"<<S[j].y<<"\tB.x:"<<dmin.x<<"\tB.y:"<<dmin.y<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment