• C++
  • 信奥1班2024暑假集训day6-真题算法专项演练-枚举算法

  • @ 2024-7-6 9:16:49

1951:【10NOIP普及组】导弹拦截

image

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010;

int n;
int a1, b1, a2, b2;

struct Point
{
    int x, y;
    int d;
    bool operator< (const Point &W)const
    {
        return d < W.d;
    }
}point[N];


int get_dist(int x1, int y1, int x2, int y2)
{
    int dx = x1 - x2;
    int dy = y1 - y2;
    return dx * dx + dy * dy;
}


int main()
{
    scanf("%d%d%d%d", &a1, &b1, &a2, &b2);
    scanf("%d", &n);

    for (int i = 0; i < n; i ++ )
    {
        int x, y;
        scanf("%d%d", &x, &y);
        point[i] = {x, y, get_dist(x, y, a1, b1)};
    }

    sort(point, point + n);
    reverse(point, point + n);

    int res = point[0].d, r = 0;
    for (int i = 1; i <= n; i ++ )
    {
        r = max(r, get_dist(point[i - 1].x, point[i - 1].y, a2, b2));
        res = min(res, point[i].d + r);
    }

    printf("%d\n", res);
    return 0;
}

1958:【12NOIP普及组】寻宝

image

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 10010, M = 110, mod = 20123;

int n, m, k;
bool st[N][M];
int x[N][M];

int main()
{
    scanf("%d%d", &n, &m);

    int res = 0;
    for (int i = 0; i < n; i ++ )
        for (int j = 0; j < m; j ++ )
            scanf("%d%d", &st[i][j], &x[i][j]);

    scanf("%d", &k);
    for (int i = 0; i < n; i ++ )
    {
        int s = 0;
        for (int j = 0; j < m; j ++ ) s += st[i][j];
        int t = x[i][k];
        res = (res + t) % mod;
        t %= s;
        if (!t) t = s;

        for (int j = k; ;j = (j + 1) % m)
        {
            if (st[i][j])
            {
                if (-- t == 0)
                {
                    k = j;
                    break;
                }
            }
        }
    }

    printf("%d\n", res);
    return 0;
}

1961:【13NOIP普及组】计数问题

image

#include <iostream>

using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;

    int res = 0;
    for (int i = 1; i <= n; i ++ )
        for (int j = i; j; j /= 10)
            if (j % 10 == x)
                res ++ ;

    cout << res << endl;

    return 0;
}

1965:【14NOIP普及组】珠心算测验 image

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 110;

int n;
int a[N];
bool st[20010];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
    for (int i = 0; i < n; i ++ )
        for (int j = 0; j < i; j ++ )
            st[a[i] + a[j]] = true;

    int res = 0;
    for (int i = 0; i < n; i ++ )  res += st[a[i]];

    printf("%d\n", res);

    return 0;
}

0 条评论

目前还没有评论...