Codeforces Round 882 (Div. 2)

这篇具有很好参考价值的文章主要介绍了Codeforces Round 882 (Div. 2)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

A. The Man who became a God 

题目分析:

B. Hamon Odyssey

题目分析:

C. Vampiric Powers, anyone?

题目分析: 


A. The Man who became a God 

Codeforces Round 882 (Div. 2),题解,c++,Codeforces

题目分析:

n个人分成k组,每一组的力量都是Codeforces Round 882 (Div. 2),题解,c++,Codeforces这样的,那么如果分成k组那么就会有k-1个力量不被统计,将力量总和减去前k-1个最大的力量就是最小的结果

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
typedef pair<int,int>pii;
const int N =105;
int a[N],sb[N];
bool cmp(int a,int b){
    return a>b;
}
signed main()
{IOS
use{
    int n,k;cin>>n>>k;cin>>a[1];
    for(int i=2;i<=n;i++){
        cin>>a[i];
        
        sb[i-1]=abs(a[i]-a[i-1]);
    }
    sort(sb+1,sb+n,cmp);int sum=0;
    for(int i=k;i<n;i++){
        sum+=sb[i];
    }cout<<sum<<endl;
}

return 0;
}

B. Hamon Odyssey

Codeforces Round 882 (Div. 2),题解,c++,Codeforces 

题目分析:

将数组分组,每个组内进行按位与运算,若想让每个组的结果加和最小,最多可以分几个组

按位与运算,是一个单调递减的过程,如果一个数字的某一位为0,那么无论多少数该位为1 ,结果都为0,对于题目来说,我们需要尽可能的将一个组的结果变为零,也即让所有的0尽可能的发挥作用,故,如果当前数按位与为零之后,将其分为一组.

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
typedef pair<int,int>pii;
const int N =2e5+7;
signed main()
{IOS
use{
    int fi=0,ans=0,x,n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        if(fi==0)fi=x,ans++;
        fi&=x;
    }
    if(!fi)ans++;
    cout<<max(1ll,ans-1)<<endl;
}

return 0;
}

C. Vampiric Powers, anyone?

Codeforces Round 882 (Div. 2),题解,c++,Codeforces

题目分析: 

给一个数组,可以在数组的末尾加上从~的异或和,求出数组最大的数可能是多少。

已知可以将~的异或和(qwq)提取出来,那么从1~-1的异或和(awa)就可以通过AllXOR^qwq=awa;

我们可以利用前缀和的思想,存下前项的异或和,我们可以通过XOR前面的异或和来获得各个小区间的异或和,最终遍历取最大值即可;文章来源地址https://www.toymoban.com/news/detail-744025.html

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define INF 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define int long long
#define pb push_back
#define vct vector
#define checkbit __builtin_popcount
#define gcd __gcd
#define use int T;cin>>T;while(T--)
#define LEN length()
#define all(a) a.begin(),a.end()
template<class T> bool mmax(T &u, T v) { return u < v ? (u = v, 1) : 0; }
template<class T> bool mmin(T &u, T v) { return u > v ? (u = v, 1) : 0; }
#define lowbit(x) (x&(-x))
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
typedef pair<int,int>pii;
signed main()
{IOS
use{
   int n;cin>>n;
		vector<int> a(n+1);
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			a[i]^=a[i-1];
		}
		vct<bool>st((1<<8|1),0);
		st[0]=1;
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=0;j<(1<<8);j++)
			{
				if(st[j]) ans=max(ans,j^a[i]);
			}
			st[a[i]]=1;
		}
		cout<<ans<<endl;

    
}
return 0;
}

到了这里,关于Codeforces Round 882 (Div. 2)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • Codeforces Round 858 (Div. 2)题解

    目录 A. Walking Master(贪心) 题面翻译 思路: 代码实现  B. Mex Master(贪心) 题面翻译: 思路: 代码实现 C. Sequence Master(数学) 题面翻译: 思路: 代码实现 YunQian is standing on an infinite plane with the Cartesian coordinate system on it. In one move, she can move to the diagonally adjacent point on the

    2023年04月08日
    浏览(9)
  • Codeforces Round 877 (Div. 2) 题解

    写了两题了,先总结一下吧。。。看了三题,都是思维题构造题,搞心态真的搞心态。。。感觉自己屁都不会,完全没有动力。。。有的有思路但是写不出来,但是思路不够成熟,练的题太少,其实这场到B题就卡住了,C题也是,题意都能读懂,但是思考的方向不对,很焦虑

    2024年02月10日
    浏览(12)
  • Educational Codeforces Round 145 Div. 2 题解

    目录 A. Garland(签到) 题面翻译 思路: 代码 B. Points on Plane(数学) 题面翻译 思路: 代码 C. Sum on Subarray(构造) 题面翻译: 思路: 代码 D. Binary String Sorting 题面翻译 思路: 代码 You have a garland consisting of 4 colored light bulbs, the color of the i-th light bulb is si. Initially, all the l

    2023年04月09日
    浏览(8)
  • Educational Codeforces Round 147 div2题解

    目录 A. Matching(签到) 思路: 代码:  B. Sort the Subarray(签到) 思路: 代码: C. Tear It Apart(枚举) 思路: 代码: D. Black Cells(模拟) 思路:  代码一: 代码二:(模仿自\\\"AG\\\"佬) An integer template is a string consisting of digits and/or question marks. A positive (strictly greater than 0) in

    2023年04月21日
    浏览(8)
  • Educational Codeforces Round 134 (Div.2) D 题解

    D. Maximum AND 给定两组序列 (a) (b) ,长度为 (n) ,现有一新序列 (c) ,长度也为 (n) 。 其中, (c_i = a_i oplus b_i) 。 定义 (f(a,b) = c_1c_2……c_n) 。 现在你可以随意编排 (b) 序列的顺序,求 (f(a,b)) 的最大值。 以下位运算均是二进制。 由于按位与的运算结果是越来越小的

    2024年02月06日
    浏览(7)
  • Educational Codeforces Round 148 (Rated for Div. 2) 题解

    总结:5.21下午VP一场,死在了A题,给我wa崩溃了,浪费了差不多一个小时,BC还挺顺畅,虽然C题是在结束后不久交上去的。。。。 思路:其实思路很简单, “ The string s a palindrome ”, 题目已经说了所给的为回文字符串,所以直接判断一半 有几种字符 即可(开始的时候计算整

    2024年02月06日
    浏览(8)
  • Codeforces Round 866 (Div. 2)

    给出一个仅由_或^组成的字符串,你可以在任意位置添加_或^字符,使得字符串满足: 任意字符要么属于^_^的一部分,要么属于^^的一部分。求最少添加的字符数量。 对于_我们只需处理没有组成^_^的_: ①如果_在首位置且左边没有^则添加^ ②如果_在尾位置且右边没有^则添加

    2023年04月25日
    浏览(8)
  • Codeforces Round 868 Div 2

    Codeforces Round 868 Div 2

    要求构造一个仅包含 (1) 和 (-1) 的长度为 (n) 的数组 (a) ,使得存在 (k) 个下标对 ((i, j), i j) 满足 (a_i times a_j = 1) 。 当有 (x) 个 (1) , (y) 个 (-1) 时,其满足条件的下标对数量为 (frac{x (x - 1)}{2} + frac{y (y - 1)}{2}) 。 由于 (n) 只有 (100) ,直接枚举 (x) 即可。

    2024年02月01日
    浏览(24)
  • Codeforces Round 871 (Div. 4)

    Codeforces Round 871 (Div. 4)

    给定n个长度为10的字符串,问其与codeforces字符串的对应下标字母不同的个数。 对于每个字符串从前往后依次和“codeforces”对应字符比较然后统计不同字母数即可 给定长度为n的数组,问连续相邻为0的最大长度 维护一个全局最大长度res,和当前连续序列的长度cnt。从前往后扫

    2024年02月03日
    浏览(9)
  • Codeforces Round 867 (Div. 3)

    从所有a[i]+i-1=t的选择种取个max即可 实际上就是取同符号乘积的最大值 找规律,发现结果与边长n的关系是:res = n * (n + 3) - (n - 2) ①当n为奇数时,除了1其他均无解 ②当n为偶数时,我们可以构造一个形如n,1,n - 2,3,...的数列 首先我们可以发现n必定出现在起始位置。如果n不在起

    2024年02月02日
    浏览(9)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包