Codeforces Round 907 (Div. 2)

Codeforces Round 907 (Div. 2)

A

判断i不为2的幂时有无出现递减

#include <bits/stdc++.h>
 
using namespace std;
const int N = 2000;
int a[N];
 
void solve()
{
    int n;
    std::cin >> n;
    
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 1; i < n; i++) {
        //i不为2的幂时出现递减
        if ((i & (i - 1)) != 0 && a[i] < a[i - 1]) {
            std::cout << "NO\n";
            return;
        }
    }
    std::cout << "YES\n"; 
}
 
int main()
{
    int T;
    cin >> T;
    while (T --)
    {
        solve();
    }
    return 0;
}

B

q的种类其实不会超过31个,因此直接模拟

#include <bits/stdc++.h>
 
using namespace std;
 
long long qp[31] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
long long book[31];
 
void solve()
{
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    while (q--)
    {
        int x;
        cin >> x;
        if (book[x])
            continue;
        book[x] = 1;
        for (int i = 1; i <= n; i++)
        {
            if (a[i] % qp[x] == 0)
            {
                a[i] += qp[x - 1];
            }
        }
    }
    memset(book, 0, sizeof(book));
    for (int i = 1; i <= n; i++)
        cout << a[i] << " ";
    cout << endl;
}
 
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

C

排序后平A从前往后打小怪,大招从后往前打大怪
发现一半的伤害是大招打出,一半的伤害是平A打出,可以简便计算

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
int a[N];

void solve()
{
    long long n, sum = 0;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    //对前一半的用A的到的连击数
    sum /= 2; 
    sort(a.begin() + 1, a.end());
    long long ans = 0;
    for (int i = n; i >= 1; i--)
    {   
        //大招
        if (sum >= a[i])
            sum -= a[i], a[i] = 0, ans++;
        else if (sum)
            a[i] -= sum, sum = 0, ans++;
    }
    //A
    for (int i = 1; i <= n; i++)
        ans += a[i];
    cout << ans << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T --)
    {
        solve();
    }
    return 0;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值