Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <iterator>
- class Point {
- public:
- Point() {}
- Point(int x, int y)
- : x_(x), y_(y) {
- }
- int x_;
- int y_;
- };
- int MAX_X = 9;
- int MAX_Y = 9;
- //std::vector<Point> inputPoints = { Point(2,1) };
- std::vector<Point> inputPoints = { Point(1,6), Point(2,1) };
- //std::vector<Point> inputPoints = { Point(1,6), Point(2,1), Point(4,4) };
- //std::vector<Point> inputPoints = { Point(2,1), Point(1,6), Point(4,4), Point(6,2), Point(7,5) };
- void getPointsInRange(const std::vector<Point> &points, std::vector<Point> &pointsRange, int startX, int stopX, int startY, int stopY) {
- std::transform(points.begin(), points.end(), std::back_inserter(pointsRange),
- [&](const Point &point) {
- if (point.x_ > startX
- && point.x_ < stopX
- && point.y_ > startY
- && point.y_ < stopY) {
- return point;
- }
- }
- );
- }
- std::vector<Point>::const_iterator getNextElement(const std::vector<Point> &points, int startX, int stopX, int startY, int stopY) {
- return find_if(points.begin(), points.end(),
- [&](const Point &point) {
- return point.x_ > startX
- && point.x_ < stopX
- && point.y_ > startY
- && point.y_ < stopY;
- }
- );
- }
- int count(const std::vector<Point> &points, int startX, int stopX, int startY, int stopY) {
- return std::count_if(points.begin(), points.end(),
- [&](const Point &point) {
- return point.x_ > startX
- && point.x_ < stopX
- && point.y_ > startY
- && point.y_ < stopY;
- }
- );
- }
- int countMaxPlots(const std::vector<Point> &points, int startX, int stopX, int startY, int stopY) {
- std::cout << "a" << std::endl;
- std::vector<Point> pointsInRange;
- getPointsInRange(points, pointsInRange, startX, stopX, startY, stopY);
- if (pointsInRange.size() == 0) {
- return 0;
- }
- else {
- int max = 0;
- for (auto it = pointsInRange.begin(); it != pointsInRange.end(); ++it) {
- std::cout << "actual " << it->x_ << " " << it->y_ << std::endl;
- if (count(points, startX, stopX, startY, stopY) == 1) {
- return 1;
- }
- int maxPlotsForPoint = std::max(
- //left + right
- { countMaxPlots(points, startX, it->x_, startY, stopY) + countMaxPlots(points, it->x_, stopX, startY, stopY),
- // bottom + top
- countMaxPlots(points, startX, stopX, startY, it->y_) + countMaxPlots(points, startX, stopX, it->y_, stopY)
- ,
- // LB + RB + LT + RT
- countMaxPlots(points, startX, it->x_, startY, it->y_) + countMaxPlots(points, it->x_, stopX, startY, it->y_)
- + countMaxPlots(points, startX, it->x_, it->y_, stopY) + countMaxPlots(points, it->x_, stopX, it->y_, stopY)
- }
- );
- if (maxPlotsForPoint > max) {
- max = maxPlotsForPoint;
- }
- }
- return max;
- }
- }
- int main()
- {
- std::cout << "Max: " << countMaxPlots(inputPoints, 0, MAX_X, 0, MAX_Y) << std::endl;
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement