Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <math.h>
- #include <algorithm>
- #include <chrono>
- #define Size Point
- using namespace std;
- int N, M, R;
- struct Point {
- int x, y;
- Point() {}
- Point(int _x, int _y) {
- x = _x;
- y = _y;
- }
- friend bool operator <(const Point& l, const Point& r);
- friend bool operator >(const Point& l, const Point& r);
- friend bool operator ==(const Point& l, const Point& r);
- };
- bool operator <(const Point& l, const Point& r) {
- if (l.y == r.y)
- return l.x < r.x;
- return l.y < r.y;
- }
- bool operator >(const Point& l, const Point& r) {
- if (l.y == r.y)
- return l.x > r.x;
- return l.y > r.y;
- }
- bool operator ==(const Point& l, const Point& r) {
- return l.x == r.x && l.y == r.y;
- }
- /* Проверка на вместимость в карту */
- bool check_olymp(Size s) {
- if (s.x > ::M || s.y > ::N)
- return false;
- return true;
- }
- /* Двойной массив относительных точек центров двух колец */
- vector<Point> build_map() {
- vector<Point> map;
- int count = 0;
- for (int x = 1; x < 2 * R; ++x) {
- for (int y = 1; y < 2 * R; ++y)
- if (x * x + y * y < 4 * R * R) {
- map.push_back(Point(x, y));
- //cout << x << '-' << y << endl;
- ++count;
- }
- }
- cout << count << endl << pow(count, 4) << endl;
- return map;
- }
- vector<Point> build_delete_map() {
- vector<Point> map;
- for (int x = 2 * R - 1; x > 1; --x)
- for (int y = 2 * R - 1; y > 1; --y)
- if (x * x + y * y >= 4 * R * R)
- map.push_back(Point(x, y));
- return map;
- }
- map<Size, int> build_full(map<Size, int> map_y, map<Size, int> map_x) {
- map<Size, int> new_map;
- for (map<Size, int>::iterator it = map_x.begin(); it != map_x.end(); ++it) {
- for (map<Size, int>::iterator _it = map_y.begin(); _it != map_y.end(); ++_it) {
- //cout << "x:" << it->first.x << "\ty:" << _it->first.y << endl;
- new_map[Size(it->first.x, _it->first.y)] = it->second * _it->second;
- }
- }
- return new_map;
- }
- map<Size, int> build_osnovanie() {
- map<Size, int> size_map;
- vector<Point> _map;
- for (int x = 1; x < 2 * R; ++x)
- _map.push_back(Point(x, 1));
- Point p1(0, 0);
- for (vector<Point>::iterator i2 = _map.begin(); i2 != _map.end(); ++i2) {
- Point p2(p1.x + (*i2).x, p1.y - (*i2).y);
- for (vector<Point>::iterator i3 = _map.begin(); i3 != _map.end(); ++i3) {
- Point p3(p2.x + (*i3).x, p2.y + (*i3).y);
- for (vector<Point>::iterator i4 = _map.begin(); i4 != _map.end(); ++i4) {
- Point p4(p3.x + (*i4).x, p3.y - (*i4).y);
- for (vector<Point>::iterator i5 = _map.begin(); i5 != _map.end(); ++i5) {
- Point p5(p4.x + (*i5).x, p4.y + (*i5).y);
- Size size = Size(p5.x - p1.x, max(p1.y, max(p3.y, p5.y)) - min(p2.y, p4.y));
- std::map<Size, int>::iterator it = size_map.find(size);
- if (it != size_map.end()) it->second++;
- else size_map[size] = 1;
- }
- }
- }
- }
- _map.clear();
- map <Size, int> __map;
- for (int y = 1; y < 2 * R; ++y)
- _map.push_back(Point(1, y));
- for (vector<Point>::iterator i2 = _map.begin(); i2 != _map.end(); ++i2) {
- Point p2(p1.x + (*i2).x, p1.y - (*i2).y);
- for (vector<Point>::iterator i3 = _map.begin(); i3 != _map.end(); ++i3) {
- Point p3(p2.x + (*i3).x, p2.y + (*i3).y);
- for (vector<Point>::iterator i4 = _map.begin(); i4 != _map.end(); ++i4) {
- Point p4(p3.x + (*i4).x, p3.y - (*i4).y);
- for (vector<Point>::iterator i5 = _map.begin(); i5 != _map.end(); ++i5) {
- Point p5(p4.x + (*i5).x, p4.y + (*i5).y);
- Size size = Size(p5.x - p1.x, max(p1.y, max(p3.y, p5.y)) - min(p2.y, p4.y));
- std::map<Size, int>::iterator it = __map.find(size);
- if (it != __map.end()) it->second++;
- else __map[size] = 1;
- }
- }
- }
- }
- return build_full(__map, size_map);
- }
- map<Size, int> build_size(vector<Point> map) {
- std::map<Size, int> size_map;
- Point p1(0, 0);
- for (vector<Point>::iterator i2 = map.begin(); i2 != map.end(); ++i2) {
- Point p2(p1.x + (*i2).x, p1.y - (*i2).y);
- for (vector<Point>::iterator i3 = map.begin(); i3 != map.end(); ++i3) {
- Point p3(p2.x + (*i3).x, p2.y + (*i3).y);
- for (vector<Point>::iterator i4 = map.begin(); i4 != map.end(); ++i4) {
- Point p4(p3.x + (*i4).x, p3.y - (*i4).y);
- for (vector<Point>::iterator i5 = map.begin(); i5 != map.end(); ++i5) {
- Point p5(p4.x + (*i5).x, p4.y + (*i5).y);
- Size size = Size(p5.x - p1.x, max(p1.y, max(p3.y, p5.y)) - min(p2.y, p4.y));
- std::map<Size, int>::iterator it = size_map.find(size);
- if (it != size_map.end()) it->second++;
- else size_map[size] = 1;
- }
- }
- }
- }
- return size_map;
- }
- //vector<tuple<Size, int>> build_size(vector<vector<Point>> map) {
- // if (R == 1) {
- // vector<tuple<Size, int>> size;
- // size.push_back(tuple<Size, int>(Size(6, 3), 1));
- // return size;
- // }
- //
- // int len_x = map.size();
- //
- // for (int i = 0; i < len_x - 1; ++i) {
- // int len_y = map[i].size();
- // for (int i2 = i; i2 < len_x; ++i2) {
- // int len_y2 = map[i2].size();
- //
- // }
- // }
- // return;
- //}
- map<Size, int> delete_this(map<Size, int> size_map, vector<Point> delete_map) {
- Point p1(0, 0);
- for (vector<Point>::iterator i2 = delete_map.begin(); i2 != delete_map.end(); ++i2) {
- Point p2(p1.x + (*i2).x, p1.y - (*i2).y);
- for (vector<Point>::iterator i3 = delete_map.begin(); i3 != delete_map.end(); ++i3) {
- Point p3(p2.x + (*i3).x, p2.y + (*i3).y);
- for (vector<Point>::iterator i4 = delete_map.begin(); i4 != delete_map.end(); ++i4) {
- Point p4(p3.x + (*i4).x, p3.y - (*i4).y);
- for (vector<Point>::iterator i5 = delete_map.begin(); i5 != delete_map.end(); ++i5) {
- Point p5(p4.x + (*i5).x, p4.y + (*i5).y);
- Size size = Size(p5.x - p1.x, max(p1.y, max(p3.y, p5.y)) - min(p2.y, p4.y));
- size_map.find(size)->second--;
- }
- }
- }
- }
- return size_map;
- }
- int main() {
- int n, m, r;
- cin >> m >> n >> r;
- ::M = m;
- ::N = n;
- ::R = r;
- //vector<Point> map = build_map();
- //std::map<Size, int> size_map = build_size(map);
- //for (std::map<Size, int>::iterator it = size_map.begin(); it != size_map.end(); ++it) {
- // cout << it->first.x << '-' << it->first.y << ":\t" << it->second << endl;
- //}
- chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
- std::map<Size, int> size_map = build_osnovanie();
- chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now();
- vector<Point> _size = build_delete_map();
- chrono::high_resolution_clock::time_point t3 = chrono::high_resolution_clock::now();
- map<Size, int> correct = delete_this(size_map, _size);
- chrono::high_resolution_clock::time_point t4 = chrono::high_resolution_clock::now();
- for (std::map<Size, int>::iterator it = size_map.begin(); it != size_map.end(); ++it) {
- cout << it->first.x << '-' << it->first.y << ":\t" << it->second << endl;
- }
- cout << "----------------------" << endl;
- for (std::map<Size, int>::iterator it = correct.begin(); it != correct.end(); ++it) {
- cout << it->first.x << '-' << it->first.y << ":\t" << it->second << endl;
- }
- chrono::duration<double> time_span1 = chrono::high_resolution_clock::duration(t2 - t1);
- chrono::duration<double> time_span2 = chrono::high_resolution_clock::duration(t3 - t2);
- chrono::duration<double> time_span3 = chrono::high_resolution_clock::duration(t4 - t3);
- cout << time_span1.count() << '\t' << time_span2.count() << '\t' << time_span3.count() << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement