以下の内容はhttps://blog.hamayanhamayan.com/entry/2018/01/21/231406より取得しました。


Perfect Squares [Codeforces Round #458 A]

http://codeforces.com/contest/914/problem/A

N要素の配列Aがある。
この中のperfect squareでない数の中で最大の数を答えよ。
xがperfect squareである -> x=y^2となるyが存在する

解法

http://codeforces.com/contest/914/submission/34407620

perfect squareであるかはyを全探索して確認すればいい。
Aの値は最大10^6なので、yは10^3くらいまで確認する。
HackポイントがAの値のうち負の数はperfect squareでないため、答えが負の数になるかもしれないという部分。

int N, A[1010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    int ans = -inf;
    rep(i, 0, N) {
        if (A[i] < 0) chmax(ans, A[i]);
        else {
            int ok = 1;
            rep(j, 0, 1010) if (j * j == A[i]) ok = 0;
            if (ok) chmax(ans, A[i]);
        }
    }
    cout << ans << endl;
}



以上の内容はhttps://blog.hamayanhamayan.com/entry/2018/01/21/231406より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14