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 875 (Div. 1) 题解

    You are given two arrays a and b both of length n. Your task is to count the number of pairs of integers ( i , j ) (i,j) ( i , j ) such that 1 ≤ i j ≤ n 1≤ij≤n 1 ≤ i j ≤ n and a i ⋅ a j = b i + b j a_i⋅a_j=b_i+b_j a i ​ ⋅ a j ​ = b i ​ + b j ​ 。 1 ≤ a i , b i ≤ n 1≤a_i,b_i≤n 1 ≤ a i ​ , b i ​ ≤ n 考虑 m i n ( a i

    2024年02月08日
    浏览(27)
  • 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日
    浏览(29)
  • 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日
    浏览(31)
  • 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日
    浏览(35)
  • Educational Codeforces Round 148 (Rated for Div. 2) 题解

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

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

    大等于2依据冒泡排序即可排序,因此判断下1即可 对每一个数字找哪一位肯定为0填0其他的填1 从后往前考虑加到当前集合或新立一个集合 从最高位开始考虑能否为1,计算能否时每个数当前位为1

    2024年02月04日
    浏览(31)
  • Codeforces Round 874 (Div. 3)

    用最少的长度为2的字符串按一定规则拼出s。规则是:前一个字符串的尾与后一个字符串的首相同。 统计s中长度为2的不同字符串数量。 给定数组a[n]和b[n],重排b后,令任意|ai−bi|≤k成立(1≤k≤n)数据保证一定有解。 将a和b分别按从小到大的顺序匹配便是最优的,一定能满足

    2024年02月05日
    浏览(30)
  • 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日
    浏览(35)
  • Codeforces Round 894 (Div. 3)

    签到题 a数组里,大于等于前一个值的a[i]会被写到b里。直接遍历b,如果b[i]比前一个小就在它前面插一个相等的值 计算反过来的长度,判断是否相等就行 对于没有重复口味的集合,能选出的方案是n*(n-1)/2 (从n个里面选2个的组合数)。二分找出需要多少不同口味的冰淇淋,

    2024年02月11日
    浏览(30)
  • Codeforces Round 881 (Div. 3)

    给定一个数组,给每个元素涂色。求最大的代价。 代价为每个颜色的代价和。 每个颜色的代价为涂了该颜色的元素的极差。 因为是极差,每个元素要么对答案有正的贡献,要么有负的贡献,要么无贡献。且正负贡献的个数要相同。 因为要最大值,自然就是想有正贡献的是最

    2024年02月09日
    浏览(31)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包