Codeforces Round #553 (Div. 2) E 贡献】的更多相关文章

https://codeforces.com/contest/1151/problem/E 题意 一条长n的链,每个点上有值\(a[i]\),定义\(f(l,r)\)为该区间的\(值\)所代表的点留下来后的联通块数量,求\(\sum^n_{l=1} \sum^n_{r=1} f(l,r)\) 题解 计算贡献,计算每个点留下后作为联通块的第一个点的情况数就是这个点的贡献 代码 #include<bits/stdc++.h> #define ll long long using namespace…
题目网址:http://codeforces.com/contest/1151/problem/D 题目大意:给出n组数对,(ai , bi),调整这n组数对的位置,最小化 ∑(ai*( i -1)+bi*(n - i))并输出结果. 题解:首先这个展开这个式子,并归变量得,i*(ai - bi)+n*bi,即这个式子之和前部分有关,后面的就是n*∑ bi,若要最小化总和,即按(ai - bi)配对,并逆序相乘即可. #include<bits/stdc++.h> #define ll lon…
题目网址:http://codeforces.com/contest/1151/problem/C 题目大意:给定奇数集和偶数集,现构造一个数组,先取奇数集中一个元素1,再取偶数集二个元素2,4,再取奇数集四个元素3,5,7,9,再取偶数集八个元素,6,8,10…… 得到 1,2,4,3,5,7,9,6,8,10,12……问这个数组的某一区间和是多少,并对1e9+7取模. 题解:对于奇数集x和偶数集y的前k项,有x=k^2,y=k*(k+1),首先,计算区间和,可以用前缀和,当计算前n项的和时,…
题目网址:http://codeforces.com/contest/1151/problem/B 题目大意:给定一个n*m的矩阵,问是否可以从每一行中选择一个数,使得这n个数异或大于0,如果可以还要输出它们的列位置 题解:首先如果a^b==0,b!=c,则a^c>0.那么考虑构造,为了方便,选取第一列的数,如果异或>0,直接输出列位置,反之则随便在一行中,找到一个与第一个不相等的数,那么由异或性质满足条件,如果n行都找不到,则无法实现. #include<bits/stdc++.h&g…
题目网址:http://codeforces.com/contest/1151/problem/A 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母,默认A与Z相邻,问最少多少次操作使得有字串是ACTG? 题解:数据量小,暴力即可,即从左向右扫,四个一组进行判断,注意,扫到Z要分析两种情况. #include<bits/stdc++.h> #define ll long long using namespace std; string a=&q…
C. Problem for Nazar time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilitie…
昨晚深夜修仙上紫记,虽然不错还是很有遗憾的. A. Maxim and Biology 看完就会做的题,然而手速跟不上 #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; typedef long long LL; const in…
https://codeforces.com/contest/1151/problem/C 题意 有两个等差数列(1,3,5,..),(2,4,6,...),两个数列轮流取1,2,4,...,\(2^n\)组成一个新的数列,然后询问区间l,r的和 题解 一开始总想着怎么计算中间那一段,其实用前缀和很好处理 数太大,第二个数也要取模才能相乘 代码 #include<bits/stdc++.h> #define ll long long using namespace std; const ll…
CodeForces1151 Maxim and Biology 解析: 题目大意 每次可以使原串中的一个字符\(+1/-1\),\(Z + 1\to A, A -1\to Z\),求至少修改多少次可以使 ACTG 是原串的子串 \(4\le |S|\le 50\) 思路: 直接暴力尝试每个子串. code #include <bits/stdc++.h> const int N = 50 + 10; const int INF = 0x3f3f3f3f; using namespace st…
传送门 A. Maxim and Biology 题意: 给出一个串s,问最少需要多少步操作使得串s包含"ACTG"这个子串,输出最少操作次数: 题解: 枚举每个位置 i,求出将 i,i+1,i+2,i+3 变为 "ACTG" 所需的最少操作次数即可: AC代码: #include<bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define ll long long #define…