NOIP真题题解-普及组(模拟一)

1. 陶陶摘苹果

来源:NOIP2005普及组 https://ac.nowcoder.com/acm/contest/233/A

解题思路:

枚举苹果,判断陶陶的身高加上凳子的高度是否大于等于苹果的高度。

#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
    int a[10];
    for (int i = 0; i < 10; i++) cin >> a[i];
 
    int height;
    cin >> height;
    height += 30;
 
    int res = 0;
    for (int i = 0; i < 10; i++)
        if (a[i] <= height)
            res++;
 
    cout << res << endl;
 
    return 0;
}

2. 不高兴的津津

来源:NOIP2004普及组 https://ac.nowcoder.com/acm/contest/232/A

解题思路:

枚举每一天,算出在校学习和在家学习的总时间的最大值。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
    int maxv = -1, p;
    for (int i = 1; i <= 7; i++)
    {
        int a, b;
        cin >> a >> b;
        if (a + b > maxv)
        {
            maxv = a + b;
            p = i;
        }
    }
 
    if (maxv > 8) printf("%d\n", p);
    else puts("0");
 
    return 0;
}

3. 校门外的树

题目来源:NOIP2005普及组 https://ac.nowcoder.com/acm/contest/233/B

解题思路:

用布尔数组表示每个树是否被移走。对于每个操作直接扫描区间中的所有位置即可。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int N = 10010;
 
int n, m;
bool st[N];
 
int main()
{
    scanf("%d%d", &m, &n);
    while (n--)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        for (int i = l; i <= r; i++) st[i] = true;
    }
 
    int res = 0;
    for (int i = 0; i <= m; i++)
        if (!st[i])
            res++;
 
    printf("%d\n", res);
 
    return 0;
}

4. 花生采摘

题目来源:NOIP2004普及组 https://ac.nowcoder.com/acm/contest/232/B

解题思路:

  • 阅读理解题,从题中可以发现整个过程是固定的,因此直接模拟即可。

  • 从初始状态开始,每次判断采摘下一位置的花生的时间是否够用

    • 如果够用,则采摘下一最大值;
    • 如果不够用,则停止;
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
 
typedef pair <int, int> PII; const int N = 30;
 
int n, m, k;
int g[N][N];
 
PII get_max()
{
    PII r = { 0, 0 };
 
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (g[r.first][r.second] < g[i][j])
                r = {
                    i, j
                };
 
    return r;
}
 
int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> g[i][j];
 
    auto t = get_max();
    if (t.first * 2 + 1 > k) puts("0");
    else
    {
        int res = g[t.first][t.second];
        k -= t.first + 1;
        g[t.first][t.second] = 0;
 
        while (true)
        {
            auto r = get_max();
            int d = abs(r.first - t.first) + abs(r.second - t.second);
 
            if (d + r.first + 1 > k) break;
            if (!g[r.first][r.second]) break;
            res += g[r.first][r.second];
            g[r.first][r.second] = 0;
            k -= d + 1;
            t = r;
        }
 
        printf("%d\n", res);
    }
 
    return 0;
}

发布了114 篇原创文章 · 获赞 98 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/github_39533414/article/details/98237755