Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <vector>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <iterator>
  9.  
  10. class Point {
  11. public:
  12. Point() {}
  13. Point(int x, int y)
  14. : x_(x), y_(y) {
  15.  
  16. }
  17.  
  18. int x_;
  19. int y_;
  20.  
  21.  
  22. };
  23.  
  24. int MAX_X = 9;
  25. int MAX_Y = 9;
  26.  
  27. //std::vector<Point> inputPoints = { Point(2,1) };
  28. std::vector<Point> inputPoints = { Point(1,6), Point(2,1) };
  29. //std::vector<Point> inputPoints = { Point(1,6), Point(2,1), Point(4,4) };
  30. //std::vector<Point> inputPoints = { Point(2,1), Point(1,6), Point(4,4), Point(6,2), Point(7,5) };
  31.  
  32.  
  33. void getPointsInRange(const std::vector<Point> &points, std::vector<Point> &pointsRange, int startX, int stopX, int startY, int stopY) {
  34. std::transform(points.begin(), points.end(), std::back_inserter(pointsRange),
  35. [&](const Point &point) {
  36. if (point.x_ > startX
  37. && point.x_ < stopX
  38. && point.y_ > startY
  39. && point.y_ < stopY) {
  40. return point;
  41. }
  42. }
  43. );
  44. }
  45.  
  46. std::vector<Point>::const_iterator getNextElement(const std::vector<Point> &points, int startX, int stopX, int startY, int stopY) {
  47. return find_if(points.begin(), points.end(),
  48. [&](const Point &point) {
  49. return point.x_ > startX
  50. && point.x_ < stopX
  51. && point.y_ > startY
  52. && point.y_ < stopY;
  53. }
  54. );
  55. }
  56.  
  57.  
  58. int count(const std::vector<Point> &points, int startX, int stopX, int startY, int stopY) {
  59. return std::count_if(points.begin(), points.end(),
  60. [&](const Point &point) {
  61. return point.x_ > startX
  62. && point.x_ < stopX
  63. && point.y_ > startY
  64. && point.y_ < stopY;
  65. }
  66. );
  67. }
  68.  
  69.  
  70. int countMaxPlots(const std::vector<Point> &points, int startX, int stopX, int startY, int stopY) {
  71. std::cout << "a" << std::endl;
  72.  
  73. std::vector<Point> pointsInRange;
  74. getPointsInRange(points, pointsInRange, startX, stopX, startY, stopY);
  75. if (pointsInRange.size() == 0) {
  76. return 0;
  77. }
  78. else {
  79. int max = 0;
  80. for (auto it = pointsInRange.begin(); it != pointsInRange.end(); ++it) {
  81. std::cout << "actual " << it->x_ << " " << it->y_ << std::endl;
  82. if (count(points, startX, stopX, startY, stopY) == 1) {
  83. return 1;
  84. }
  85.  
  86. int maxPlotsForPoint = std::max(
  87. //left + right
  88. { countMaxPlots(points, startX, it->x_, startY, stopY) + countMaxPlots(points, it->x_, stopX, startY, stopY),
  89.  
  90. // bottom + top
  91. countMaxPlots(points, startX, stopX, startY, it->y_) + countMaxPlots(points, startX, stopX, it->y_, stopY)
  92. ,
  93.  
  94. // LB + RB + LT + RT
  95. countMaxPlots(points, startX, it->x_, startY, it->y_) + countMaxPlots(points, it->x_, stopX, startY, it->y_)
  96. + countMaxPlots(points, startX, it->x_, it->y_, stopY) + countMaxPlots(points, it->x_, stopX, it->y_, stopY)
  97. }
  98. );
  99. if (maxPlotsForPoint > max) {
  100. max = maxPlotsForPoint;
  101. }
  102. }
  103. return max;
  104. }
  105.  
  106. }
  107.  
  108. int main()
  109. {
  110. std::cout << "Max: " << countMaxPlots(inputPoints, 0, MAX_X, 0, MAX_Y) << std::endl;
  111. getchar();
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement