Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> split_string(string);
  6. string solve(int r1, int r2, vector<int> position, vector<int> acceleration) {
  7.     double t;
  8.     double deltaX=(double)position[0];
  9.     cout <<r1<< " " << r2<< " "<< position[0]<<position[1]<<position[2] << endl;
  10.     cout << acceleration[0]<<acceleration[1]<<acceleration[2] << endl;
  11.     double deltaY=(double)position[1];
  12.     double deltaZ=(double)position[2];
  13.     double accX = (double)acceleration[0];
  14.     double accY = (double)acceleration[1];
  15.     double accZ = (double)acceleration[2];
  16.     double numerador = abs(2.0 * (deltaX*accX + deltaY*accY + deltaZ*accZ));
  17.     double denominador = accX*accX+accY*accY+accZ*accZ;
  18.     t=sqrt(numerador/denominador);
  19.    
  20.     double S = deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ + 2*(deltaX*accX+deltaY*accY+deltaZ*accZ)*t*t/2.0 + denominador*t*t*t*t/4.0;
  21.     if(S<=(r1+r2)*(r1+r2))return "YES";
  22.     return "NO";
  23. }
  24.  
  25. int main()
  26. {
  27.     ofstream fout(getenv("OUTPUT_PATH"));
  28.  
  29.     int t;
  30.     cin >> t;
  31.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  32.  
  33.     for (int t_itr = 0; t_itr < t; t_itr++) {
  34.         string r1R2_temp;
  35.         getline(cin, r1R2_temp);
  36.  
  37.         vector<string> r1R2 = split_string(r1R2_temp);
  38.  
  39.         int r1 = stoi(r1R2[0]);
  40.  
  41.         int r2 = stoi(r1R2[1]);
  42.        
  43.         string position_temp_temp;
  44.         getline(cin, position_temp_temp);
  45.         //1
  46.         vector<string> position_temp = split_string(position_temp_temp);
  47.  
  48.         vector<int> position(3);
  49.  
  50.         for (int i = 0; i < 3; i++) {
  51.             int position_item = stoi(position_temp[i]);
  52.  
  53.             position[i] = position_item;
  54.         }
  55.  
  56.         string acceleration_temp_temp;
  57.         getline(cin, acceleration_temp_temp);
  58.  
  59.         vector<string> acceleration_temp = split_string(acceleration_temp_temp);
  60.  
  61.         vector<int> acceleration(3);
  62.  
  63.         for (int i = 0; i < 3; i++) {
  64.             int acceleration_item = stoi(acceleration_temp[i]);
  65.  
  66.             acceleration[i] = acceleration_item;
  67.         }
  68.        
  69.         //2
  70.         string position_temp_temp2;
  71.         getline(cin, position_temp_temp2);
  72.  
  73.         vector<string> position_temp2 = split_string(position_temp_temp2);
  74.  
  75.         for (int i = 0; i < 3; i++) {
  76.             int position_item = stoi(position_temp2[i]);
  77.  
  78.             position[i] = position_item - position[i];
  79.         }
  80.  
  81.         string acceleration_temp_temp2;
  82.         getline(cin, acceleration_temp_temp2);
  83.  
  84.         vector<string> acceleration_temp2 = split_string(acceleration_temp_temp2);
  85.  
  86.         for (int i = 0; i < 3; i++) {
  87.             int acceleration_item2 = stoi(acceleration_temp2[i]);
  88.  
  89.             acceleration[i] = acceleration_item2 - acceleration[i];
  90.         }
  91.  
  92.         string result = solve(r1, r2, position, acceleration);
  93.  
  94.         fout << result << "\n";
  95.     }
  96.  
  97.     fout.close();
  98.  
  99.     return 0;
  100. }
  101.  
  102. vector<string> split_string(string input_string) {
  103.     string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  104.         return x == y and x == ' ';
  105.     });
  106.  
  107.     input_string.erase(new_end, input_string.end());
  108.  
  109.     while (input_string[input_string.length() - 1] == ' ') {
  110.         input_string.pop_back();
  111.     }
  112.  
  113.     vector<string> splits;
  114.     char delimiter = ' ';
  115.  
  116.     size_t i = 0;
  117.     size_t pos = input_string.find(delimiter);
  118.  
  119.     while (pos != string::npos) {
  120.         splits.push_back(input_string.substr(i, pos - i));
  121.  
  122.         i = pos + 1;
  123.         pos = input_string.find(delimiter, i);
  124.     }
  125.  
  126.     splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  127.  
  128.     return splits;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement