// No.455 冬の大三角 // https://yukicoder.me/problems/no/455 // #include #include #include #include #include #include using namespace std; pair solve(vector>& stars, int H, int W); struct Point { double x; double y; }; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int H, W; cin >> H >> W; vector> stars; string t; getline(cin, t); vector field; for (int y = 0; y < H; ++y) { getline(cin, t); for (int x = 0; x < W; ++x) { if (t[x] == '*') stars.push_back(make_pair(x, y)); } field.push_back(t); } pair ans = solve(stars, H, W); field[ans.second][ans.first] = '*'; for (int y = 0; y < H; ++y) cout << field[y] << endl; } pair solve(vector>& stars, int H, int W) { random_device seed_gen; mt19937 engine(seed_gen()); uniform_int_distribution<> dist_x(0, W-1); uniform_int_distribution<> dist_y(0, H-1); while (true) { int x = dist_x(engine); int y = dist_y(engine); if (x == stars[0].first && y == stars[0].second) continue; if (x == stars[1].first && y == stars[1].second) continue; Point ab = {static_cast(x) - stars[0].first, static_cast(y) - stars[0].second}; Point ac = {static_cast(x) - stars[1].first, static_cast(y) - stars[1].second}; double cross = ab.x * ac.y - ab.y * ac.x; if (abs(cross) > 0.0001) return make_pair(x, y); } }