1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| const double pi = acos(-1);
class Circle { public: int r, x, y; Circle(int _r = 0, int _x = 0, int _y = 0) : r(_r), x(_x), y(_y) {}
bool operator< (const Circle& rhs) const { if(r != rhs.r) return r < rhs.r; if(x != rhs.x) return x < rhs.x; return y < rhs.y; } };
ostream& operator<< (ostream& os, const Circle& c) { char buf[128]; sprintf(buf, " (%d,%d,%d)", c.r, c.x, c.y); return os << buf; }
bool inRange(int x, int l, int r) { if(l > r) return inRange(x, r, l); return l <= x && x <= r; }
vector<string> lines; vector<Circle> ans;
void init() { lines.clear(); ans.clear(); }
int main() { freopen("input.txt", "r", stdin); int T; scanf("%d", &T);
_rep(kase, 1, T) { init();
int w, h; scanf("%d%d", &w, &h);
lines.resize(h); _for(i, 0, h) cin >> lines[i];
// then we solve the problem _rep(r, 5, 50) _rep(x, r, w - r) _rep(y, r, h - r) { int tot = 0, black = 0;
// then enumerate _for(i, 0, 100) { double deg = 2 * pi * (rand() / (RAND_MAX + 1.0)); int cx = (int)(x + r * cos(deg) + 0.5), cy = (int)(y + r * sin(deg) + 0.5);
if(inRange(cx, 0, w - 1) && inRange(cy, 0, h - 1) && lines[cy][cx] == '1') black++; tot++;
if(tot > 10 && black * 2 < tot) break; }
if(black / (double) tot > 0.8) ans.push_back(Circle(r, x, y)); }
printf("Case %d: ", kase); cout << ans.size(); _for(i, 0, ans.size()) cout << ans[i]; cout << endl; } }
|