跳到正文

题解

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

曾煜晗2015约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年4月26日
收录
2026年6月7日
更新
2026年11月14日
篇幅
约 3 分钟
题目
P16353

版本

  1. v1当前

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

10分

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

代码
n = 1

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

100分

考虑分类讨论:

当 x>0x > 0 且 y>0y > 0:

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

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

当 x>0x > 0 且 y<0y < 0:

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

当 x<0x < 0 且 y<0y < 0:

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

C++
#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 见祖宗

C++
#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 此题。

原文