Codeforces Round #672 (Div. 2)(A、B、C1、D)

涉及知识点:

  • 思维

solution

  • 题意大概就是使用不超过 n*(n - 1) / 2 - 1次操纵使其完全递增
  • 其实其只要不是完全递减的序列就好了

std:

#include <iostream>
using namespace std;
 
int main()
{
    int t;
    int n;
    
    cin >> t;
    
    while(t --)
    {
        cin >> n;
        bool tf = false;
        int a,b;
        b = 1e9 + 10;
        for(int i = 0;i < n;i ++)
        {
            cin >> a;
            if(b > a){
                b = a;
            }
            else{
                tf = true;
            }
        }
        
        if(tf){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
        
        
    }
    
    
    
    return 0;
}

涉及知识点:

  • 思维

solution

  • 题意大概就是 The task is to calculate the number of such pairs (i,j) that i<j and ai & aj≥ai⊕aj, where & denotes the bitwise AND operation, and ⊕ denotes the bitwise XOR operation.
  • 其实就是二进制的拓展,稍微懂一点二进制就能完全做出这个题
#include <iostream>
#include <cstring>
using namespace std;
 
const int N = 60;
 
long long a[N];
 
int main()
{
    int t;
    int n;
    cin >> t;
    while(t --)
    {
        cin >> n;
        int x;
        long long res = 0;
        memset(a,0,sizeof a);
        for(int i = 0;i < n;i ++)
        {
            cin >> x;
            for(int i = 31;i >= 0;i --)
            {
                if(x >> i & 1){
                    a[i]++;
                    break;
                }
            }
        }
        
        
        for(int i = 0;i <= 31;i ++)
        {
            // cout << a[i] << ' ';
            res += (0 + a[i] - 1) * a[i] / 2;
        }
        // cout << endl;
        cout << res << endl;
        
        
    }
    
    return 0;
}

涉及知识点:

  • dp

solution

  • 题意大概就是找出最大值,a1-a2+a3-a4····这个序列的最大值
  • 我认为是对背包的一点拓展
  • 对于当前这个物品有选和不选两种选择,还有如果选了当前这个数变为总数为偶数还是奇数
  • 不选或者选完为偶数
  • dp[i][0] = max(dp[i - 1][0],dp[i - 1][1] - x);
  • 不选或者是选完为奇数
  • dp[i][1] = max(dp[i - 1][1],dp[i - 1][0] + x);
#include <iostream>
#include <cstring>
using namespace std;
 
const int N = 3e5 + 10;
 
long long dp[N][2];
 
 
int main()
{
    int t, n,p;
    
    cin >> t;
    
    while(t --)
    {
        dp[0][0] = dp[0][1] = 0;
        
        cin >> n >> p;
        long long x;
        long long a = 0,b = 0;
        for(int i = 1;i <= n;i ++)
        {
            cin >> x;
            dp[i][0] = max(dp[i - 1][0],dp[i - 1][1] - x);
            dp[i][1] = max(dp[i - 1][1],dp[i - 1][0] + x);
        }
        
        cout << max(dp[n][0],dp[n][1]) << endl;
        
    }
    
    
        
    return 0;
}

涉及知识点:

  • 优先队列

solution

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值