跳到正文

题解

随机化强强强

ExCh_dd2014_Gcdunk约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年8月28日
收录
2026年8月31日
更新
2026年11月17日
篇幅
约 1 分钟
题目
P17328

版本

  1. v1当前

显然,随机一个长度 5000050000 的序列成功率很高,考虑随机化。

我取了 10001000 个,然后随机取一个,这样子的错误概率比滚木低。而且你也卡不掉。

C++
#include <bits/stdc++.h>
using namespace std;
string p[1005];
int main()
{
    string s = "UDLR";
    srand(time(0));
    int F = 1000;
    string A;
    while(F--)
    {
        int G = 50000;
        string ans;
        while(G--)
            ans += s[rand() % 4];
        p[F] = ans;
    }
    cout << p[rand() % F + 1];
}
原文