Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int dotProduct(int vect_A[], int vect_B[])
  6. {
  7. int product = 0;
  8.  
  9. for (int i = 0; i < 3; i++)
  10.  
  11. product = product + vect_A[i] * vect_B[i];
  12.  
  13. return product;
  14. }
  15.  
  16. double get_norm (int vetor[])
  17. {
  18. double norm=0;
  19. for (int i = 0; i<3; i++)
  20.  
  21. norm = norm + vetor[i]*vetor[i];
  22.  
  23. norm = sqrt(norm);
  24. return norm;
  25. }
  26.  
  27. int main (){
  28.  
  29. int t, pos_ini1[3], pos_ini2[3], acele1[3], acele2[3], dif_pos[3], dif_ace[3], r1, r2, resposta[10010];
  30. double norm_a, prod_int, delta, norm_r;
  31.  
  32. cin>>t;
  33.  
  34. for (int i = 0; i<t; i++)
  35. {
  36. cin>>r1;
  37. cin>>r2;
  38.  
  39. for(int j = 0; j<3;j++)
  40. {
  41. cin>>pos_ini1[j];
  42. }
  43. for(int j = 0; j<3;j++)
  44. {
  45. cin>>acele1[j];
  46. }
  47. for(int j = 0; j<3;j++)
  48. {
  49. cin>>pos_ini2[j];
  50. }
  51. for(int j = 0; j<3;j++)
  52. {
  53. cin>>acele2[j];
  54. }
  55. for(int j = 0; j<3;j++)
  56. {
  57. dif_pos[j]=pos_ini1[j]-pos_ini2[j];
  58. dif_ace[j]=(acele1[j]- acele2[j])/2;
  59. }
  60. prod_int = dotProduct(dif_pos, dif_ace);
  61. norm_a = get_norm(dif_ace);
  62. norm_r = get_norm(dif_pos);
  63. delta = prod_int*prod_int - norm_a*norm_a*(norm_r*norm_r - (r1+r2)*(r1+r2));
  64. if(norm_a>0)
  65. {
  66. if(delta>=0)
  67. {
  68. if((-prod_int+sqrt(delta))>0 || (-prod_int-sqrt(delta))>0)
  69. resposta[i]=1;
  70. else
  71. resposta[i]=0;
  72. }
  73. else
  74. resposta[i]=0;
  75. }
  76. else
  77. resposta[i]=0;
  78. }
  79. for (int i = 0; i < t ; i++)
  80. {
  81. if(resposta[i]==1)
  82. cout<<"YES"<<endl;
  83. else
  84. cout<<"NO"<<endl;
  85. }
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement