题目大意:求一段数(l到r)的按位与结果不为零需要删除中间元素的最小个数 思路:按位与使得结果不为0只要有某一位全是1即可,所以只要统计每一位1的个数,用总个数减去1的个数就是某一位0的个数 删除包含0最少的那一位就是最少需要删除的个数 1 # include<iostream> 2 # include<bits/stdc++.h> 3 using namespace std; 4 # define int long long 5 # define endl "\n&qu…
题目链接:https://codeforces.com/contest/1368/problem/D 题意 给出一个大小为 $n$ 的数组 $a$,每次可以选两个下标不同的元素,一个赋为二者相与的值,同时一个赋为二者相或的值,计算 $\sum_{i=1}^n a_i^2$ 的最大值. 题解 即重新分配二进制下所有位的 $1$,贪心构造即可. 证明 重新分配的正确性 如: \begin{equation} 110 \end{equation} \begin{equation} 101 \end{e…
题意:有\(n\)个数,选择某一对数使二者分别\(or\)和\(and\)得到两个新值,求操作后所有数平方和的最大值. 题解:不难发现每次操作后,两个数的二进制表示下的\(1\)的个数总是不变的,所以要让平方最大,那么只能使大的尽可能大,那我们就统计每个数二进制下的每一位上\(1\)的个数,然后每个数的位置都尽可能的分配\(1\)就行了. 代码: ll n,x; ll cnt[N]; ll ans; int main() { ios::sync_with_stdio(false);cin.tie…
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B. Tape 显然就是先找一个长的把所有的全部覆盖,然后可以在上面丢掉\(k-1\)段间隙. 那么把两两之间的间隙长度拿出来排序就可以了. C. Meaningless Operations 如果\(a\)不等于\(2^k-1\)的形式,那么令\(S=2^k-1\),其中\(2^{k-1}<a<2…
Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Output Print one integer: the maximum number of triples you can form. Sample Input 10 62 3 3 3 4 4 4 5 5 6 Sample Output 3 题解:动态规划,对这种状态定义不熟悉,主要还是没有发现最优方…
Codeforces Beta Round #18 (Div. 2 Only) http://codeforces.com/contest/18 A 暴力 #include<bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define sqr(x) ((x)*(x)) #define maxn 500005 typedef long lo…
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给出n个数,问从一个数到另外一个不同数的最长距离是多少. 题解: 从前往后,从后往前扫两遍即可.证明可用反证法,这里略去. #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int n; int c[N]; i…
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^(k-1)+a2*b^(k-2)+...+ak*b^0的奇偶性. 题解: 暴力求模2意义下的值就好了. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int n; int b,k; int a[…
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置都是不同字符,求可能的最长串长度. 枚举一下\(a\)开头还是\(b\)开头,那么接下来就被唯一确定了. #include<iostream> #include<cstdio> using namespace std; int a,b,c;long long ans; int main…
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补完了,所以先把 A-F 放上来. A. Parity 保存 %2 的值就可以了. const int N = 1e5 + 7; int b, k, a[N], ans; int main() { read(b), read(k); for (int i = 1; i <= k; ++i) read(…