Codeforces Round #840 (Div. 2) and Enigma 2022 - Cybros LNMIIT题解

这场好难我是废物,掉大分了

A. Absolute Maximization

利用|找最大值和&找最小值即可

#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define endl '\n'

void solve()
{
	int n;
	cin >> n;
	int maxn = 0,minn = 1023;
	for(int i = 0,c;i < n;++i)
	{
		cin >> c;
		maxn |= c;
		minn &= c;
	}
	cout << maxn - minn << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

	int t = 1;
	cin >> t;
	while(t--)
		solve();
    
    return 0;
}

B. Incinerate

万万没想到,思维题竟然没有错在思维上,而是错在了代码上(被fst了)

思路简单,按照 p [ i ] p[i] p[i]从小到大排序后直接遍历判断一遍即可。

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vint vector<int>

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<array<int, 2>> a(n);
    int maxn = 0;
    for (int i = 0; i < 2; ++i)
    {
        int k = i ^ 1;
        for (int j = 0; j < n; ++j)
        {
            cin >> a[j][k];
            maxn = max(maxn, a[j][1]);
        }
    }
    sort(all(a));
    int res = m;
    for(int i = 0;i < n;++i)
    {
    	while(res < a[i][1] && m > 0)
    	{
    		m -= a[i][0];
    		res += m;
    	}
    	if(m < 0)
    		break;
    }
    if (res < maxn)
        puts("NO");
    else
        puts("YES");
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while (t--)
        solve();

    return 0;
}

C. Another Array Problem

c有三种情况,分别为 n = 2 , n = 3 , n ≥ 4 n=2,n=3,n \ge 4 n=2,n=3,n4

  1. n = 2 n=2 n=2:取 a b s ( a [ 1 ] − a [ 2 ] ) ∗ 2 和 a [ 1 ] + a [ 2 ] abs(a[1] - a[2]) * 2和a[1] + a[2] abs(a[1]a[2])2a[1]+a[2]的最大值即可

  2. n ≥ 4 n \ge 4 n4:这种情况下为$a[max_i] * n

    1. n = 3 n=3 n=3时,分四种情况:

      1. 最大值在下标1或下标3的位置: a [ m a x i ] ∗ 3 a[max_i] * 3 a[maxi]3
      2. 最大值在中间:下列三种情况取最大值
        1. 三数之和
        2. 最大值和最小值之差的绝对值*3
        3. 次大值*3
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vint vector<int>

void solve()
{
    int n;
    cin >> n;
    vint a(n + 1);
    int idx = 0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        if (a[i] > a[idx])
            idx = i;
    }
    if (n == 2)
        cout << max(abs(a[2] - a[1]) * 2, a[1] + a[2]) << endl;
    else if (n == 3)
    {
        if (idx == 1 || idx == 3)
            cout << a[idx] * 3 << endl;
        else
        {
            int x = min(a[1], a[3]), y = max(a[1], a[3]);
            int k = a[2] - x;
            cout << max({k * 3,y * 3,a[1] + a[2] + a[3]}) << endl;
        }
    }
    else
        cout << a[idx] * n << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值