Codeforces Round 1002 (Div. 2)(部分题解)

补题链接

A. Milya and Two Arrays

 思路:题意还是比较好理解,分析的话我加了一点猜的成分,对a,b数组的种类和相加小于4就不行,蒋老师的乘完后小于等于2也合理。

AC代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n, m, k;
    cin >> n;
    auto check = [&]() ->int
    {
        set<int> s;
        for (int i = 0; i<n; i++){
            int x; cin >> x;
            s.insert(x);
        }
        return s.size();
    };
    if (check()+check() > 3) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;  cin >> t;
    while (t--)
    {
        solve();
    }
    
    return 0;
}

B. Cost of the Array

 思路:这道题有点贪心在里面。

想要最小的代价,那从最小的代价为1开始做打算,怎样来计算1呢,当为前n-k+2个(不包含第一个)里面存在不为1,则分成的k块的第2块为此块,能使代价为最小1.

此外,想让代价最大,就得当k等于n,并且每偶数块是从1开始的递增。

因此我们可以来完善第一部分,当k不等于n时,代价不为1的话,就说明蓝色部分全为1,因为k小于n,所以第二位与第三位肯定是1,可以结合在一起使得最小的代价为2,综上整合一下为AC代码:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
void solve()
{
    int n, m, k;
    cin >> n >> k;
    vi a(n);
    for (auto &it : a) cin >> it;
    if (k == n){
        for (int i = 1; i<n; i+=2){
            if (a[i]*2 != i+1){
                cout << (i+1)/2 << endl;
                return ;
            }
        }
        cout << k/2+1 << endl;
    }
    else {
        for (int i = 1; i<=n-k+1; i++){
            if (a[i] != 1){
                cout << 1 << endl;
                return ;
            }
        }
        cout << 2 << endl;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wirepuller_king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值