Codeforces 1208F Bits And Pieces】的更多相关文章

题意:给你一个序列a, 问a[i] ^ (a[j] & a[k])的最大值,其中i < j < k. 思路:我们考虑对于每个a[i]求出它的最优解.因为是异或运算,所以我们从高位向低位枚举,如果这一位a[i]是0,我们就在a[i]的右边找两个位置让它们按位与起来这位是1.那么,我们贪心的保留可以通过按位与凑出某个二进制数的最靠右的两个位置.这个可以通过dp的方式预处理出来.之后,我们枚举每一个数a[i],先找出它的哪些位是0,之后从高位到低位枚举,判断这一位是否可以变成1.如果之前已经…
题面传送门 题意:求 \(\max\limits_{i<j<k}a_i|(a_j\&a_k)\). \(1\leq n \leq 10^6,1\leq a_i\leq 2\times 10^6\) u1s1 这题算高维前缀和里不那么 sb 的题,虽然代码也很简单. 很容易想到一个贪心,从高到低枚举每一位,能填 \(1\) 就填 \(1\),不能填 \(1\) 就填 \(0\). 于是本题转化为一个问题:是否存在某个 \(i,j,k\) 使得 \(x\) 为 \(a_i|(a_j\&am…
传送门. 位运算的比较基本的题. 考虑枚举\(i\),然后二进制位从大到小考虑, 对于第\(w\)位,如果\(a[i][w]=1\),那么对\(j.k\)并没有什么限制. 如果\(a[i][w]=0\),那么我们希望\((a[j]~and~a[k])[w]=1\),结合前面的限制,就是给定\(x\),问有没有\(x∈a[j]~and~a[k](i<j<k)\). 那么这应该是做一个高维后缀max和次max就能解决的事. Code: #include<bits/stdc++.h> #…
CF1208F Bits And Pieces 传送门 思路 这里要运用SOS-DP的思路(\(\text{Sum over Subsets}\)).我在另外一篇博客里介绍过,如有需要可以搜索一下我的博客. SOS-DP是记录每个\(mask\)所有子集的信息,而这道题只需要记录每个\(mask\)所有超集的信息即可.\(dp[mask]\)记录的是能满足\(mask\)是其的子集的所有数中坐标最大的两个.我们枚举\(a_i\),然后贪心的按位取就可以了.具体细节可以看代码. 代码 #inclu…
C. Bits time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Let's denote as  the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple que…
题意: 让你输出长度为n的某个序列,然后给你m个变量. 每次给某个数赋值的代价是 假设赋值a=7那么代价是3,因为7的二进制位中有3个1. 要求最后总代价最小. 输出总共要进行操作的次数,和最小代价. 先吐槽下,早期的cf题很多没有官方题解,只找到两篇中文题解...第一篇完全没搞懂大神再说什么.建图的方法是在第二篇中受到启发[虽然也没搞懂大神在说什么] 首先说下这题对我的启示: 1.现在对状态这个词越发有深的理解了,很多题目只要理解了某个抽象意义上的状态,加上他们之间的转换的方式[也有很多人说是…
B. Sheldon and Ice Pieces time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon play…
A. Bits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Let's denote as  the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple…
题意:给定一个区间,求区间中的一个数,这个数表示成二进制的时候,数字1的个数最多! 如果有多个这样的数字,输出最小的那个! 思路:对左区间的这个数lx的二进制 从右往左将0变成1,直到lx的值大于右区间的值rx! #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int main(){ long long a, b; i…