193030

Група точки

Apr 4th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4. #include <vector>
  5. #include <sstream>
  6. #include <time.h>
  7. #include <stdio.h>
  8. #include <math.h>       /* sqrt */
  9.  
  10. using namespace std;
  11. stringstream stream;
  12. //vector <int> niz(0);
  13. //int numbers[] = {};
  14.  
  15. vector <int> cordinateX(0);
  16. vector <int> cordinateY(0);
  17.  
  18. string input;
  19. int nBroiTochki = 0;
  20. int D_razstoqnie = 0;
  21.  
  22.  
  23. void solve()
  24. {
  25.    // D_razstoqnieMin = 1;
  26.  //  cout << "vliza v solve" << endl;
  27.     for(int j =1; j<=D_razstoqnie; j++)
  28.     {
  29.    //    cout << "vliza vuv 1 for" << endl;
  30.  
  31.     int  groupsCounter = 0;
  32.     for(int i =0; i<=nBroiTochki; i+=2)
  33.     {
  34.         //cout << "vtori for" << endl;
  35.         double tempX1 = cordinateX[i];
  36.         double tempY1 = cordinateY[i];
  37.         double tempX2 = cordinateX[i+1];
  38.         double tempY2 = cordinateY[i+1];
  39.         double distanceBetweenTwoPoints = sqrt(pow((tempX2-tempX1),2) +pow((tempY2-tempY1),2));
  40.         if(distanceBetweenTwoPoints>j)
  41.         {
  42.             groupsCounter++;
  43.         }
  44.  
  45.     }
  46.         int temp = groupsCounter+1;
  47.  
  48.         if((temp== nBroiTochki)&& (nBroiTochki>2))
  49.         {
  50.             groupsCounter++;
  51.          //   cout << "vliza tuk" << endl;
  52.         }
  53.      //   cout << "Groups counter: " << groupsCounter << endl;
  54.         //
  55.  
  56.    
  57.              cout <<  groupsCounter << " ";
  58.    
  59.     //    cout <<  groupsCounter << " ";
  60.        
  61.        // cout << "j kolko e " << j<< endl;
  62.  
  63.     }
  64.  
  65. }
  66. long sstoi(const char *s) // custom stoi function
  67. {
  68.  
  69.  
  70.     long i;
  71.     i = 0;
  72.     while(*s >= '0' && *s <= '9')
  73.     {
  74.         i = i * 10 + (*s - '0');
  75.         s++;
  76.     }
  77.     return i;
  78. }
  79. int main()
  80. {
  81.     clock_t tStart = clock();
  82.     /* Do your stuff here */
  83.  
  84.     int tempNumber = 0;
  85.    while(cin >>nBroiTochki)
  86.    {
  87.        cin.ignore();
  88.        cin >> D_razstoqnie;
  89.       cin.ignore();
  90.        getline(cin,input);
  91.        stream.str(input);
  92.     //   cout << "NbroiTochki " << nBroiTochki << endl;
  93.        int n = nBroiTochki;
  94.        while(n--)
  95.        {
  96.            stream >> tempNumber;
  97.            cordinateX.push_back(tempNumber);
  98.            stream >> tempNumber;
  99.            cordinateY.push_back(tempNumber);
  100.  
  101.  
  102.        }
  103.        stream.clear();
  104.         //cout << "NbroiTochki " << nBroiTochki << endl;
  105.       //  cout << "D razstoqnie"<< D_razstoqnie << endl;
  106.        /* for(int i =0; i<nBroiTochki; i++)
  107.         {
  108.  
  109.             cout << "cordinate X val: " << cordinateX[i] << "cordinate Y val: " << cordinateY[i] << endl;
  110.         }
  111.         */
  112.         solve();
  113.  
  114.  
  115.     cordinateX.clear();
  116.     cordinateY.clear();
  117.  
  118.  
  119.    }
  120.  
  121.  
  122.  
  123.     //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  124.  
  125.  
  126.  
  127. }
  128. // Работи с много output
Add Comment
Please, Sign In to add comment