Advertisement
NHumme

Untitled

Apr 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <vector>
  6. #include <string>
  7. #include <set>
  8. #include <stack>
  9. #include <queue>
  10. #include <deque>
  11. #include <fstream>
  12. #include <ctime>
  13. using namespace std;
  14.  
  15. #define TASK "path"
  16.  
  17. struct item {
  18.     double x, y;
  19.     int type;
  20. };
  21.  
  22. int main() {
  23.  
  24.     srand(time(0));
  25.  
  26. #ifdef _DEBUG
  27.     //freopen("debug.in", "r", stdin);
  28.     //freopen("debug.out", "w", stdout);
  29. #else
  30.     //freopen(TASK".in", "r", stdin);
  31.     //freopen(TASK".out", "w", stdout);
  32.     //freopen("input.txt", "r", stdin);
  33.     //freopen("output.txt", "w", stdout);
  34. #endif // _DEBUG
  35.  
  36.     ios_base::sync_with_stdio(0);
  37.     cin.tie(0);
  38.     cout.tie(0);
  39.     cout.precision(6);
  40.  
  41.     ofstream fout;
  42.     for (int i = 1; i <= 5; i++) {
  43.         string filename = "";
  44.         filename += (i < 10 ? '0' : char(i / 10 + '0'));
  45.         filename += char(i % 10 + '0');
  46.         fout.open(filename + ".tst");
  47.  
  48.         int n = rand() % 1001 + 1, m = rand() % 1001 + 1;
  49.         fout << n << " " << m << "\n";
  50.         vector < item > preps(n), places(m);
  51.         for (int k = 0; k < n; k++) {
  52.             preps[k].type = rand() % 3 + 1;
  53.             preps[k].x = rand() % 10001;
  54.             preps[k].y = rand() % 10001;
  55.             fout << preps[k].type << " " << preps[k].x << " " << preps[k].y << "\n";
  56.         }
  57.         for (int k = 0; k < m; k++) {
  58.             places[k].type = rand() % 3 + 1;
  59.             places[k].x = rand() % 10001;
  60.             places[k].y = rand() % 10001;
  61.             fout << places[k].type << " " << places[k].x << " " << places[k].y << "\n";
  62.         }
  63.  
  64.         fout.close();
  65.         fout.open(filename + ".ans");
  66.  
  67.         item ans = places[0];
  68.         double sadness, xx, yy, sans = 1e9;
  69.         int type;
  70.  
  71.         for (int a = 0; a < m; a++) {
  72.             sadness = 0;
  73.             xx = places[a].x;
  74.             yy = places[a].y;
  75.             type = places[a].type;
  76.             for (int b = 0; b < n; b++) {
  77.                 double tmp = sqrt((preps[b].x - xx) * (preps[b].x - xx) + (preps[b].y - yy) * (preps[b].y - yy));
  78.                 sadness += tmp * (type == preps[b].type ? 1 : 2);
  79.             }
  80.             if (sadness < sans || sadness == sans && (xx < ans.x || xx == ans.x && yy < ans.y)) {
  81.                 ans = places[a];
  82.                 sans = sadness;
  83.             }
  84.         }
  85.  
  86.         fout << ans.x << " " << ans.y;
  87.     }
  88.  
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement