#define _CRT_NONSTDC_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #include #include #include #include //#include //#include //#include #ifdef _MSC_VER #include #include #include #include #include #include #include int __builtin_clz(unsigned int n) { unsigned long index; _BitScanReverse(&index, n); return 31 - index; } int __builtin_ctz(unsigned int n) { unsigned long index; _BitScanForward(&index, n); return index; } namespace std { inline int __lg(int __n) { return sizeof(int) * 8 - 1 - __builtin_clz(__n); } } #else #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif /** compro_io **/ /* tuple */ // out namespace aux { template struct tp { static void output(std::ostream& os, const T& v) { os << std::get(v) << ", "; tp::output(os, v); } }; template struct tp { static void output(std::ostream& os, const T& v) { os << std::get(v); } }; } template std::ostream& operator<<(std::ostream& os, const std::tuple& t) { os << '['; aux::tp, 0, sizeof...(Ts) - 1>::output(os, t); return os << ']'; } template std::basic_ostream& operator<<(std::basic_ostream& os, const Container& x); /* pair */ // out template std::ostream& operator<<(std::ostream& os, const std::pair& p) { return os << "[" << p.first << ", " << p.second << "]"; } // in template std::istream& operator>>(std::istream& is, std::pair& p) { return is >> p.first >> p.second; } /* container */ // out template std::basic_ostream& operator<<(std::basic_ostream& os, const Container& x) { bool f = true; os << "["; for (auto& y : x) { os << (f ? "" : ", ") << y; f = false; } return os << "]"; } // in template < class T, class = decltype(std::begin(std::declval())), class = typename std::enable_if::value>::type > std::istream& operator>>(std::istream& is, T& a) { for (auto& x : a) is >> x; return is; } std::ostream& operator<<(std::ostream& os, const std::vector& v) { std::string s(v.size(), ' '); for (int i = 0; i < v.size(); i++) s[i] = v[i] + '0'; os << s; return os; } std::ostream& operator<<(std::ostream& os, const std::vector>& m) { for (const auto& v : m) os << v << '\n'; return os; } /* struct */ template auto operator<<(std::ostream& out, const T& t) -> decltype(out << t.stringify()) { out << t.stringify(); return out; } /* setup */ struct IOSetup { IOSetup(bool f) { if (f) { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } std::cout << std::fixed << std::setprecision(15); } } iosetup(true); /** string formatter **/ template std::string format(const std::string& f, Ts... t) { size_t l = std::snprintf(nullptr, 0, f.c_str(), t...); std::vector b(l + 1); std::snprintf(&b[0], l + 1, f.c_str(), t...); return std::string(&b[0], &b[0] + l); } template std::string stringify(const T& x) { std::ostringstream oss; oss << x; return oss.str(); } /* dump */ #define DUMPOUT std::cerr std::ostringstream DUMPBUF; #define dump(...) do{DUMPBUF<<" ";DUMPBUF<<#__VA_ARGS__<<" :[DUMP - "<<__LINE__<<":"<<__FUNCTION__<<"]"< void dump_func(Head&& head, Tail&&... tail) { DUMPBUF << head; if (sizeof...(Tail) == 0) { DUMPBUF << " "; } else { DUMPBUF << ", "; } dump_func(std::move(tail)...); } /* timer */ class Timer { double t = 0, paused = 0, tmp; public: Timer() { reset(); } static double time() { #ifdef _MSC_VER return __rdtsc() / 3.0e9; #else unsigned long long a, d; __asm__ volatile("rdtsc" : "=a"(a), "=d"(d)); return (d << 32 | a) / 3.0e9; #endif } void reset() { t = time(); } void pause() { tmp = time(); } void restart() { paused += time() - tmp; } double elapsed_ms() const { return (time() - t - paused) * 1000.0; } }; /* rand */ struct Xorshift { uint64_t x = 88172645463325252LL; void set_seed(unsigned seed, int rep = 100) { x = uint64_t((seed + 1) * 10007); for (int i = 0; i < rep; i++) next_int(); } unsigned next_int() { x = x ^ (x << 7); return x = x ^ (x >> 9); } unsigned next_int(unsigned mod) { x = x ^ (x << 7); x = x ^ (x >> 9); return x % mod; } unsigned next_int(unsigned l, unsigned r) { x = x ^ (x << 7); x = x ^ (x >> 9); return x % (r - l + 1) + l; } // inclusive double next_double() { return double(next_int()) / UINT_MAX; } } rnd; /* shuffle */ template void shuffle_vector(std::vector& v, Xorshift& rnd) { int n = v.size(); for (int i = n - 1; i >= 1; i--) { int r = rnd.next_int(i); std::swap(v[i], v[r]); } } /* split */ std::vector split(std::string str, const std::string& delim) { for (char& c : str) if (delim.find(c) != std::string::npos) c = ' '; std::istringstream iss(str); std::vector parsed; std::string buf; while (iss >> buf) parsed.push_back(buf); return parsed; } template inline void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } template auto make_vector(T x, int arg, Args ...args) { if constexpr (sizeof...(args) == 0)return std::vector(arg, x); else return std::vector(arg, make_vector(x, args...)); } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = double; //using ld = boost::multiprecision::cpp_bin_float_quad; using pii = std::pair; using pll = std::pair; using namespace std; template void print_vector(const vector& v) { for (int i = 0; i < v.size(); i++) { cout << (i ? " " : "") << v[i]; } cout << '\n'; } constexpr int di[] = { 0, -1, 0, 1 }; constexpr int dj[] = { -1, 0, 1, 0 }; const string d2c = "LURD"; char c2d[256]; constexpr int N = 20, T = 1000; constexpr int min_wall = 100, max_wall = 200; constexpr double init_wall_prob = (min_wall + max_wall) * 0.5 / (N * (N - 1) * 2); constexpr double init_weight = 1.0, update_weight = 1.0; constexpr int si = 0, sj = 0, ti = N - 1, tj = N - 1; constexpr double inf = 1e9; double success_prob; int main() { { int buf; cin >> buf >> buf >> buf; success_prob = (100.0 - buf) / 100.0; c2d['L'] = 0; c2d['U'] = 1; c2d['R'] = 2; c2d['D'] = 3; } double hprob[N][N - 1]; // 壁っぽさ double hweight[N][N - 1]; // 重み(事前情報的な) bool hfixed[N][N - 1]; // true なら壁はない double vprob[N - 1][N]; double vweight[N - 1][N]; bool vfixed[N - 1][N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N - 1; j++) { hprob[i][j] = vprob[j][i] = init_wall_prob; hweight[i][j] = vweight[j][i] = init_weight; hfixed[i][j] = vfixed[j][i] = false; } } auto get_cost = [&](int i, int j, int d) { if (d == 0) return hfixed[i][j - 1] ? 0.0 : hprob[i][j - 1]; if (d == 1) return vfixed[i - 1][j] ? 0.0 : vprob[i - 1][j]; if (d == 2) return hfixed[i][j] ? 0.0 : hprob[i][j]; if (d == 3) return vfixed[i][j] ? 0.0 : vprob[i][j]; assert(false); return -1.0; }; // (ti,tj) まで最も壁っぽくなさそうなルートで移動する auto guess = [&]() { double dist[N][N]; int prev[N][N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dist[i][j] = inf; prev[i][j] = -1; } } using Edge = tuple; priority_queue, greater> pq; dist[si][sj] = 0; pq.emplace(dist[si][sj], si, sj); while (!pq.empty()) { auto [mincost, i, j] = pq.top(); pq.pop(); if (dist[i][j] < mincost) continue; for (int d = 0; d < 4; d++) { int ni = i + di[d], nj = j + dj[d]; if (ni < 0 || ni >= N || nj < 0 || nj >= N) continue; double cost = dist[i][j] + get_cost(i, j, d); if (chmin(dist[ni][nj], cost)) { dist[ni][nj] = cost; prev[ni][nj] = d; pq.emplace(cost, ni, nj); } } } string path; { int i = ti, j = tj, d = prev[i][j]; while (d != -1) { path += d2c[d]; i -= di[d]; j -= dj[d]; d = prev[i][j]; } reverse(path.begin(), path.end()); } return path; }; auto update = [&](const string& g, const int length) { assert(length < g.size()); // equal なら終了しているはず int i = 0, j = 0; for (int k = 0; k < length; k++) { int d = c2d[g[k]], ni = i + di[d], nj = j + dj[d]; // (i,j)-(ni,nj) に壁はない if (d == 0) hfixed[i][j - 1] = true; if (d == 1) vfixed[i - 1][j] = true; if (d == 2) hfixed[i][j] = true; if (d == 3) vfixed[i][j] = true; i = ni; j = nj; } { int d = c2d[g[length]], ni = i + di[d], nj = j + dj[d]; // (i,j)-(ni,nj) は壁の可能性がある if (d == 0) { hprob[i][j - 1] = (hprob[i][j - 1] * hweight[i][j - 1] + update_weight) / (hweight[i][j - 1] + update_weight); hweight[i][j - 1] += update_weight; } if (d == 1) { vprob[i - 1][j] = (vprob[i - 1][j] * vweight[i - 1][j] + update_weight) / (vweight[i - 1][j] + update_weight); vweight[i - 1][j] += update_weight; } if (d == 2) { hprob[i][j] = (hprob[i][j] * hweight[i][j] + update_weight) / (hweight[i][j] + update_weight); hweight[i][j] += update_weight; } if (d == 3) { vprob[i][j] = (vprob[i][j] * vweight[i][j] + update_weight) / (vweight[i][j] + update_weight); vweight[i][j] += update_weight; } } }; for (int turn = 0; turn <= T; turn++) { auto g = guess(); cout << g << endl; // predict int length; cin >> length; // result if (length == -1) break; update(g, length); // update } return 0; }