非常求助!!!!!!!,几乎一样的代码,悬关
查看原帖
非常求助!!!!!!!,几乎一样的代码,悬关
637788
kimi0705楼主2024/4/3 22:45
#include <bits/stdc++.h>
using namespace std;
const int maxa = 1e5 + 5, maxb = 50;
int a, b, n, f[maxa][maxb];
int dfs(int x, int y) {
    if (pow(x, y) >= n) return f[x][y] = 2;
    if (f[x][y]) return f[x][y];
    return f[x][y] = 3 - min(dfs(x, y + 1), dfs(x+ 1, y));
}
string s[3] = {"Missing", "Stas", "Masha"};
int main() {
    cin >> a >> b >> n;
    if (a == 1 and pow(2, b) >= n) return puts("Missing"), 0;
    cout << s[dfs(a, b)];
}

能过,但是一下不仅过不了,还MLE了

#include <bits/stdc++.h>
using namespace std;
const int maxa = 1e5 + 5, maxb = 50;
int a, b, n, f[maxa][maxb];
int dfs(int x, int y) {
    if (pow(x, y) >= n) return f[x][y] = 2;
    if (f[x][y]) return f[x][y];
    return f[x][y] = 3 - min(dfs(x + 1, y), dfs(x, y + 1));
}
string s[3] = {"Missing", "Stas", "Masha"};
int main() {
    cin >> a >> b >> n;
    if (a == 1 and pow(2, b) >= n) return puts("Missing"), 0;
    cout << s[dfs(a, b)];
}
2024/4/3 22:45
加载中...