rodrwan

the traveling orienteerer

Apr 23rd, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int casos, routes, check, pcont;
  10.     double rx, ry;
  11.     float **cord;
  12.     while(casos != 0, cin >> casos)
  13.     {
  14.        cord = new float *[casos];
  15.        for(int i=0; i<casos; i++){
  16.           cord[i] = new float[2];
  17.        }
  18.        for(int i=0; i<casos; i++){
  19.            for (int j=0; j<2; j++){
  20.                cin >> cord[i][j];
  21.            }
  22.        }
  23.        cin >> routes;
  24.        for (int i=0; i<routes; i++)
  25.        {
  26.            int *pt;
  27.            double res =0;
  28.            cin >> check;
  29.            pt = new int[check];
  30.            for (int j=0; j<check; j++)
  31.            {
  32.                cin >> pcont;
  33.                pt[j] = pcont;
  34.            }
  35.            
  36.            for (int k=0; k<check-1; k++)
  37.            {
  38.                double cord_x2 = cord[pt[k+1]][0];
  39.                double cord_x1 = cord[pt[k]][0];
  40.                double w = cord_x2-cord_x1;
  41.                double cord_y2 = cord[pt[k+1]][1];
  42.                double cord_y1 = cord[pt[k]][1];
  43.                double z = cord_y2-cord_y1;
  44.                rx = pow(w,2);
  45.                ry = pow(z,2);
  46.                res += sqrt(rx + ry);
  47.            }
  48.            cout << (int)res << endl;
  49.            delete pt;
  50.        }
  51.        delete cord;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment