AtCoder-agc025_d.cpp 977 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int color_for_distance(int x, int y, int distance_squared) {
  4. while (distance_squared % 4 == 0) {
  5. distance_squared /= 4;
  6. x /= 2;
  7. y /= 2;
  8. }
  9. if (distance_squared & 1) return (x + y) & 1;
  10. return x & 1;
  11. }
  12. int main() {
  13. ios::sync_with_stdio(false);
  14. cin.tie(nullptr);
  15. int n, d1, d2;
  16. cin >> n >> d1 >> d2;
  17. vector<vector<pair<int, int>>> bucket(4);
  18. for (int x = 0; x < 2 * n; ++x) {
  19. for (int y = 0; y < 2 * n; ++y) {
  20. int key = 2 * color_for_distance(x, y, d1)
  21. + color_for_distance(x, y, d2);
  22. bucket[key].push_back({x, y});
  23. }
  24. }
  25. auto best = max_element(bucket.begin(), bucket.end(),
  26. [](const auto &a, const auto &b) { return a.size() < b.size(); });
  27. for (int i = 0; i < n * n; ++i) {
  28. cout << (*best)[i].first << ' ' << (*best)[i].second << '\n';
  29. }
  30. return 0;
  31. }