[レビュー] NOIPの試験のトピックLuogu P1005

思考

これはテストを考えての質問ですが、何も難易度についてシミュレートしていない場合。まず、二人は会うとすぐに背を向ける、そして二人の男を入れ替えるを見て、彼らは、彼らが振り向くとなし、卵と一緒に行くことを見つけるだろう、人々はまだ少数の人々です。だから、コードを直接置きます。

コード

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <utility>

int nextInt()
{
    int num = 0;
    char c;
    bool flag = false;
    while ((c = std::getchar()) == ' ' || c == '\r' || c == '\t' || c == '\n');
    if (c == '-')
        flag = true;
    else
        num = c - 48;
    while (std::isdigit(c = std::getchar()))
        num = num * 10 + c - 48;
    return (flag ? -1 : 1) * num;
}

int main()
{
    int n, l, p, maxv = 0, minv = 0;
    l = nextInt();
    n = nextInt();
    for (int i = 1; i <= n; i++)
    {
        p = nextInt();
        maxv = max(maxv, max(l - p + 1, p));
        minv = max(minv, min(l - p + 1, p));
    }
    std::cout << minv << ' ' << maxv << std::endl;
#ifdef __EDWARD_EDIT
    std::cin.get();
    std::cin.get();
#endif
    return 0;
}
公開された40元の記事 ウォンの賞賛0 ビュー5151

おすすめ

転載: blog.csdn.net/edward00324258/article/details/78387745