【题目解析】汉中校区11/29周六晚比赛

~ 2025-12-13 10:41:32

【题目解析】汉中校区11/29周六晚比赛

A. MB 还是 MiB?

满分参考代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b;
    char x, y;
    cin >> a >> x >> y;
    if (y == 'i')
        b = 1024;
    else
        b = 1000;
    if (x == 'K')
        cout << a * b << "\n";
    else if (x == 'M')
        cout << a * b * b << "\n";
    else if (x == 'G')
        cout << a * b * b * b << "\n";
    return 0;
}

B. 优化代码 2

满分参考代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    long long i, num;
    for (i = 1;; i++)
    {
        // i*i+1 对应的 n
        num = i * i + 1 - i;
        if (num > n)
            break;
    }
    i--;
    num = i * i + 1 - i;
    cout << i * i + 1 + (n - num);
    return 0;
}

C. 比大小 Pro

满分参考代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;

    bool neg = false;
    if (a[0] == '-' && b[0] != '-')
    {
        cout << "second";
        return 0;
    }
    if (a[0] != '-' && b[0] == '-')
    {
        cout << "first";
        return 0;
    }
    if (a[0] == '-')
        neg = true;

    int aL = 0, bL = 0;
    while (aL != (int)a.size() - 1 &&
           (a[aL] == '-' || a[aL] == '0'))
        aL++;
    while (bL != (int)b.size() - 1 &&
           (b[bL] == '-' || b[bL] == '0'))
        bL++;

    int ans = 0; // 正数时的大小关系
    if ((int)a.size() - aL > (int)b.size() - bL)
        ans = 1;
    else if ((int)a.size() - aL < (int)b.size() - bL)
        ans = 2;
    else
    {
        for (int i = aL, j = bL; i < a.size(); i++, j++)
        {
            if (a[i] > b[j])
            {
                ans = 1;
                break;
            }
            if (a[i] < b[j])
            {
                ans = 2;
                break;
            }
        }
    }
    if (ans == 0)
        cout << "same";
    else if (ans == 1 && !neg ||
             ans == 2 && neg)
        cout << "first";
    else
        cout << "second";
    return 0;
}

D. 按行排序按列排序

满分参考代码

#include <bits/stdc++.h>
using namespace std;
int n, op, pos, x, y;
int a[1005][1005];
int num[1005];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    for (int t = 1; t <= n; t++)
    {
        cin >> op >> x;
        if (op == 1)
        {
            for (int i = 1; i <= n; i++)
                num[i] = a[x][i];
            sort(num + 1, num + n + 1);
            for (int i = 1; i <= n; i++)
                a[x][i] = num[i];
        }
        if (op == 2)
        {
            for (int i = 1; i <= n; i++)
                num[i] = a[i][x];
            sort(num + 1, num + n + 1);
            for (int i = 1; i <= n; i++)
                a[i][x] = num[i];
        }
    }
    for (int t = 1; t <= n; t++)
    {
        cin >> x >> y;
        cout << a[x][y] << "\n";
    }
    return 0;
}


我们会审查剪贴板内容,并对发布不合适内容的同学进行相应的处理