Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. struct Point {
  5.     double x;
  6.     double y;
  7.     Point() = default;
  8.     Point(double _x, double _y) : x(_x),
  9.                                   y(_y) {}
  10. };
  11.  
  12. struct Polygon {
  13.     std::vector<Point> points;
  14.     Polygon() = default;
  15.     explicit Polygon(std::vector<Point> &_points) : points(_points) {}
  16.     Polygon(std::initializer_list<Point> &_points) : points(_points) {}
  17. };
  18.  
  19. typedef Polygon Path;
  20.  
  21.  
  22.  
  23. struct Graph {
  24. private:
  25.     std::vector<Point> points;
  26.     std::vector<std::vector<int> > g;
  27.  
  28.     std::vector<int> p; //used in dfs
  29.     std::vector<int> used; // used in dfs
  30.     void dfs(int v) {
  31.         used[v] = true;
  32.         for (auto u : g[v]) {
  33.             if (!used[u]) {
  34.                 p[u] = v;
  35.                 dfs(v);
  36.             }
  37.         }
  38.     }
  39. public:
  40.     Graph() = default;
  41.     /* finds path in graph. Returns empty path if and only if path doesn't exist */
  42.     Path find_path(int s, int t) {
  43.         size_t n = points.size();
  44.         p.assign(n, -1);
  45.         used.assign(n, false);
  46.         Path ans;
  47.         dfs(s);
  48.         if (p[t] == -1) {
  49.             return ans;
  50.         }
  51.         int cur = t;
  52.         while (cur != s) {
  53.             ans.points.emplace_back(points[cur]);
  54.             cur = p[cur];
  55.         }
  56.         ans.points.emplace_back(points[cur]);
  57.         return ans;
  58.     }
  59. };
  60.  
  61. class Map {
  62. private:
  63.     std::vector<Polygon> hedges;
  64.     double height;
  65.     double width;
  66. public:
  67.     Map() : height(0), width(0), hedges() {}
  68.  
  69.     Map(std::initializer_list<Polygon> &_hedges, double _height, double _width) : hedges(_hedges),
  70.                                                                                   height(_height),
  71.                                                                                   width(_width) {}
  72.  
  73.     Map(std::vector<Polygon> &_hedges, double _height, double _width) : hedges(_hedges),
  74.                                                                       height(_height),
  75.                                                                       width(_width) {}
  76.  
  77.     Map(double _height, double _width) : height(_height), width(_width) {}
  78.  
  79.  
  80.     Graph make_graph() {
  81.         //making graph
  82.     }
  83.  
  84.     Path find_path(Point a, Point b) {
  85.         //finding path in graph
  86.     }
  87.  
  88.  
  89. };
  90.  
  91.  
  92.  
  93.  
  94. int main() {
  95.     Map map(480, 960);
  96.  
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement