视频题解


A

等差数列 [a,b,c][a,b,c] 一定满足 a+c=2×ba+c=2\times b,即总合 a+b+c=3×ba+b+c=3\times b

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b, c;
    cin >> a >> b >> c;
    if ((a+b+c) % 3 == 0 && (a+b+c) / 3 * 2 == (max({a,b,c}) + min({a,b,c})))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

B

能放下数量的上限即为 n×m3\lfloor\frac{n\times m}3\rfloor,在常规情况下都是可以拼成的。

特殊情况是某条边长为 22 时, n×m3\lfloor\frac{n\times m}3\rfloor 可能会算大,要修改运算顺序

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    long long M, N;
    cin >> M >> N;
    
    if (M > N) {
        swap(M, N);
    }
    
    long long ans;
    
    if (M == 2) {
        ans = (N / 3) * 2;
    } 
    else {
        ans = (M * N) / 3;
    }
    
    cout << ans << endl;
    return 0;
}

C

判断成功条件:

  1. S1S_1S2S_2 的一段前缀
  2. S2S_2 的非前缀部分必须全为数字
#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s1, s2;
    cin >> s1 >> s2;

    bool flag = true;

    if (s2.substr(0, s1.size()) != s1)
    {
        flag = false;
    }
    else
    {
        for (int i = s1.size(); i < s2.size(); ++i)
        {
            if (!isdigit(s2[i]))
            {
                flag = false;
                break; 
            }
        }
    }

    cout << (flag ? "Yes" : "No") << endl;

    return 0;
}

D

按照题意模拟即可

#include <bits/stdc++.h>
using namespace std;

int main()
{
    double x; 
    int a;    
    double b;
    cin >> x;
    cin >> a >> b;

    int tot = 0;   // 总拉人头数
    double sum = 0.0; // 累计贡献金额
    int cur_a = a; // 当前档次需要拉的人数
    double cur_b = b;   // 当前档次每人贡献值

    while (sum < x)
    {
        // 计算当前档次能贡献的总金额
        double cur_tot = cur_a * cur_b;

        // 剩余需要的金额
        double remain = x - sum;

        if (sum + cur_tot <= x)
        {
            // 情况1:当前档次全部拉完仍不够,累加全部人数和金额
            tot += cur_a;
            sum += cur_tot;

            // 更新下一档参数
            cur_a += 2;
            cur_b /= 2;
        }
        else
        {
            // 情况2:只需拉当前档次的部分人即可凑够
            // 计算需要的人数(向上取整,确保金额足够)
            int t = ceil(remain / cur_b);
            tot += t;
            sum += t * cur_b; // 此时sum ≥x,退出循环
            break;
        }
    }

    cout << tot << endl;

    return 0;
}

E

因为每组小数组的相对位置在重组之后依旧保持,所以其本身就必须升序。再判断所有的数据是否刚好连续即可

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    int f = 1, pre = 0;
    for (int i = 1; i <= n; i++)
    {
        pre = 0;
        int m;
        cin >> m;
        while (m--)
        {
            int x;
            cin >> x;
            if (pre >= x)
                f = 0;
            pre = x;
            a.push_back(x);
        }
    }
    if (f == 0)
    {
        cout << "No";
        return 0;
    }
    sort(a.begin(), a.end());
    for(int i = 1; i < a.size(); i++) {
		if(a[i] != a[i-1] + 1) {
        	cout << "No";
			return 0;
		}
	}
    cout << "Yes";

    return 0;
}


F

分别将 a,ba,b 进行质因数分解,并记录下相应的指数再叠加,即为对 a×ba\times b 质因数分解的结果。记为:

a×b=p1k1p2k2...pnkna\times b=p_1^{k_1}p_2^{k_2}...p_n^{k_n}

则最后分解出的 xyx^yxx 最小时,即为 yy 最大,即为 gcd(k1,k2...kn)gcd(k_1,k_2...k_n)

再计算出 $x=p_1^{\frac{k_1}y}p_2^{\frac{k_2}y}p_n^{\frac{k_n}y}$

注意需要手写 powpow,自带函数会有精度问题

#include <bits/stdc++.h>
using namespace std;

map<long long, int> f;
void fact(long long num) {
    
    for (long long i = 2; i * i <= num; i++) {
        if (num % i == 0) {
            int cnt = 0;
            while (num % i == 0) { cnt++; num /= i; }
            f[i] += cnt;
        }
    }
    if (num > 1)  f[num] += 1;
}
long long power(long long base, int exp) {
    long long result = 1;
    while (exp > 0) {
        result *= base;
        exp--;
    }
    return result;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t;
    cin >> t;

    while (t--) {
		f.clear();
        long long A, B;
        cin >> A >> B;

        fact(A);
        fact(B);

        long long y = 0;
        for (auto [p, cnt] : f) 
            if (y == 0) y = cnt; 
			else y = __gcd(y, (long long)cnt);
        

        long long x = 1;
        for (auto [p, cnt] : f)  x *= power(p, cnt / y);

        cout << x << " " << y << "\n";
    }

    return 0;
}

0 条评论

目前还没有评论...