题解:P16353 「Diligent-OI R3 A」说好不哭

· · 题解

题解:P16353 「Diligent-OI R3 A」说好不哭

10分

注意到“说明/提示”部分:

n = 1

简单推断可得当 x = y 时有解,否则无解。
预期得分:10分。

100分

考虑分类讨论:

当 x > 0 且 y > 0:

首先可以判断 y 是最小的。
给出证明: 采用反证,若 y 不为最小,则最小子段和为最小的那个数,与条件矛盾,故上述成立。
y 为最小,则所有数都大于等于 y,故只要 n \times y \le x 即可。

由于题目给出了 x > y,所以排除 x < 0 且 y > 0。

当 x > 0 且 y < 0:

当 n >= 2 时,则有通解x,y,0,0……
因为此时 x 必定大于 y,此时数列的最大,最小子段和正好为x,y。
当 n < 2 时,回到十分解法:当 x = y 则有解,否则无解。

当 x < 0 且 y < 0:

用反证法同样可以证明 x 是最大的。
于是我们就可以轻松的推断出 n \times x \ge y 即可。
代码如下:

#include <bits/stdc++.h>
using namespace std;

int t, n, x, y;
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n >> x >> y;
        if (n == 1) cout << (x == y ? "YES" : "NO") << endl;
        else if (x > 0 && y > 0) cout << (y * n <= x ? "YES" : "NO") << endl;
        else if (x < 0 && y < 0) cout << (x * n >= y ? "YES" : "NO") << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

预期得分:50分

不开 long long 见祖宗

#include <bits/stdc++.h>
using namespace std;
#define int long long

int t, n, x, y;
signed main()
{
    cin >> t;
    while (t--)
    {
        cin >> n >> x >> y;
        if (n == 1) cout << (x == y ? "YES" : "NO") << endl;
        else if (x > 0 && y > 0) cout << (y * n <= x ? "YES" : "NO") << endl;
        else if (x < 0 && y < 0) cout << (x * n >= y ? "YES" : "NO") << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

预期得分:100分
恭喜你 AC 此题。