[ create a new paste ] login | about

Link: http://codepad.org/MhrE7eaX    [ raw code | output | fork ]

C++, pasted on Nov 4:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

void build_list(int n, double r, std::vector<std::pair<double, int> >& res)
{
	for (int x = 0; x < n; ++x)
	{
		for (int y = 0; y < x; ++y) if (x > 0 && y > 0)
		{
			const double base_angle = atan2(y, x);
			const double delta_angle = asin(r / (sqrt (x*x + y*y)));
			res.push_back(std::make_pair(base_angle - delta_angle, 1));
			res.push_back(std::make_pair(base_angle + delta_angle, -1));
		}
	}
	std::sort(res.begin(), res.end());
}

int main()
{
	std::vector<std::pair<double, int> > vec;
	build_list(100, 0.02, vec);
	std::cout << vec.size() << "\n";
}


Output:
1
9702


Create a new paste based on this one


Comments: