mfgnik

Untitled

Jun 27th, 2020
1,622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <vector>
  2. #include <unordered_set>
  3. #include <iostream>
  4. #include <set>
  5.  
  6. template<class T, class TIter = typename T::iterator, class TVal = typename T::value_type>
  7. class PairedImpl {
  8.     T& m_t;
  9. public:
  10.     class Iter {
  11.         TIter m_it;
  12.     public:
  13.         Iter(const TIter & it) : m_it(it)  {}
  14.  
  15.         bool  operator!=(const Iter& it)   {         return m_it != it.m_it; }
  16.         Iter& operator++()                 { ++m_it; return *this; }
  17.         const Iter & operator *() const    {         return *this; }
  18.         const TVal & current_point()      const    {         return *m_it; }
  19.         const TVal & next_point()     const    {         return *std::next(m_it); }
  20.     };
  21.  
  22.     PairedImpl(T& t) : m_t(t) {}
  23.  
  24.     Iter begin() { return Iter(m_t.begin()); }
  25.  
  26.     Iter end() {
  27.         TIter end = m_t.end();
  28.         return Iter(m_t.empty() ? end : --end);
  29.     }
  30. };
  31.  
  32. template<class T>
  33. PairedImpl<T> Paired(T& t) {
  34.     return PairedImpl<T>(t);
  35. }
  36.  
  37. struct Point {
  38.     int x, y;
  39.  
  40.     Point(int x, int y) : x(x), y(y) {}
  41.  
  42.     bool operator<(const Point& other) const {
  43.         return x < other.x or x == other.x and y < other.y;
  44.     }
  45. };
  46.  
  47.  
  48. int main() {
  49.         std::set<Point> points_set;
  50.         int points_amount;
  51.         std::cin >> points_amount;
  52.         for (int index = 0; index < points_amount; ++index) {
  53.             int x, y;
  54.             std::cin >> x >> y;
  55.             points_set.emplace(x, y);
  56.         }
  57.         std::unordered_set<int> x_lines, y_lines;
  58.        for (auto pair : Paired(points_set)) {
  59.            if (pair.current_point().x == pair.next_point().x && pair.current_point().y < pair.next_point().y) {
  60.                y_lines.insert(pair.current_point().y + 1);
  61.            } else {
  62.                x_lines.insert(pair.current_point().x + 1);
  63.            }
  64.        }
  65.        std::cout << y_lines.size() + x_lines.size() << "\n";
  66.        for (auto line : y_lines) {
  67.            std::cout << "y " << line << "\n";
  68.        }
  69.     for (auto line : x_lines) {
  70.         std::cout << "x " << line << "\n";
  71.     }
  72. };
Advertisement
Add Comment
Please, Sign In to add comment