Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #ifdef LOCAL
  5. #define _GLIBCXX_DEBUG
  6. #endif
  7. #include <bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. #define forn(i, n) for (int i = 0; i < int(n); ++i)
  12. #define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
  13. #define sz(c) int((c).size())
  14. #define all(c) (c).begin(), (c).end()
  15. #define fst first
  16. #define snd second
  17. #define pb push_back
  18. #define mp(x, y) make_pair(x, y)
  19.  
  20. using ll = long long;
  21. using vi = vector<int>;
  22. using pii = pair<int, int>;
  23.  
  24. #define FILE_NAME "a"
  25.  
  26. #ifdef LOCAL
  27. #define eprintf(args...) fprintf(stderr, args), fflush(stderr)
  28. #else
  29. #define eprintf(args...) ;
  30. #endif
  31.  
  32. struct cir
  33. {
  34. int x0, y0, r;
  35.  
  36. void read ()
  37. {
  38. assert(scanf(" %d %d %d", &x0, &y0, &r) == 3);
  39. assert(r >= 0);
  40. }
  41. };
  42.  
  43. int n;
  44. vector<cir> v;
  45.  
  46. bool read() {
  47. if (scanf("%d", &n) < 1) {
  48. return 0;
  49. }
  50.  
  51. v.resize(n);
  52. forn (i, n)
  53. v[i].read();
  54.  
  55. return 1;
  56. }
  57.  
  58. #ifdef LOCAL
  59. const int len = 20;
  60. #else
  61. const int len = 256;
  62. #endif
  63.  
  64. using T = double;
  65. const T inf = 1e9;
  66.  
  67. void solve() {
  68. bool bad = false;
  69. forn (i, n)
  70. bad |= v[i].r == 0;
  71.  
  72. if (bad)
  73. {
  74. printf("Circles without representation were detected!\n");
  75. forn (i, n) if (v[i].r == 0)
  76. printf("Unable to build circle %d %d %d\n", v[i].x0, v[i].y0, v[i].r);
  77. return;
  78. }
  79.  
  80. vector<string> data(len, string(len, '.'));
  81.  
  82. auto put = [&] (int x, int y, int dig)
  83. {
  84. x %= len, y %= len;
  85. if (x < 0)
  86. x += len;
  87. if (y < 0)
  88. y += len;
  89.  
  90. data[y][x] = '0' + dig;
  91. };
  92.  
  93. const vi dx {0, +1, +1};
  94. const vi dy {-1, -1, 0};
  95.  
  96. forn (i, n)
  97. {
  98. int r = v[i].r, x0 = v[i].x0, y0 = v[i].y0;
  99. const int color = (i + 1) % 10;
  100.  
  101. auto go_put = [&] (int x, int y)
  102. {
  103. put(x0 + x, y0 + y, color);
  104. put(x0 - x, y0 + y, color);
  105. put(x0 - x, y0 - y, color);
  106. put(x0 + x, y0 - y, color);
  107. };
  108.  
  109. int x = 0, y = r;
  110.  
  111. while (x != r || y != 0)
  112. {
  113. go_put(x, y);
  114.  
  115. int bx = -1, by = -1;
  116. T best = inf;
  117.  
  118. forn (d, 3)
  119. {
  120. int nx = x + dx[d], ny = y + dy[d];
  121. T cur = fabs(sqrt((ll)nx * nx + (ll)ny * ny) - r);
  122. if (cur < best)
  123. {
  124. best = cur;
  125. bx = nx;
  126. by = ny;
  127. }
  128. }
  129.  
  130. assert(best != inf);
  131. x = bx, y = by;
  132. }
  133.  
  134. go_put(x, y);
  135. }
  136.  
  137. forn (i, len)
  138. printf("%s\n", data[i].c_str());
  139. }
  140.  
  141. int main() {
  142. #ifdef LOCAL
  143. freopen(FILE_NAME ".in", "r", stdin);
  144. freopen(FILE_NAME ".out", "w", stdout);
  145. #endif
  146.  
  147. while (read()) {
  148. solve();
  149. }
  150.  
  151. #ifdef LOCAL
  152. eprintf("Time: %.10f\n", clock() * 1.0 / CLOCKS_PER_SEC);
  153. #endif
  154.  
  155. return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement