B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si,…
传送门 Description Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike"…
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers…
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly onecharacter from the st…
如果一开始就满足题意,不用变换. 否则,如果对一对ai,ai+1用此变换,设新的gcd为d,则有(ai - ai+1)mod d = 0,(ai + ai+1)mod d = 0 变化一下就是2 ai mod d = 0 2 ai+1 mod d = 0 也就是说,用两次变换之后,gcd至少扩大2倍,于是,最优方案就是我们将所有的奇数都变成偶数. 只需要找出所有奇数段,答案就是sigma([奇数段的长度/2]+(奇数段的长度 mod 2 ==1 ?)). #include<cstdio> #i…
Codeforces Round #410 (Div. 2) A B略..A没判本来就是回文WA了一次gg C.Mike and gcd problem 题意:一个序列每次可以把\(a_i, a_{i+1}\)换成\(a_i-a_{i+1},a_i+a_{i+1}\),最小次数使gcd不为1 题解: 玩一下发现: 奇数 奇数 \(\rightarrow\) 偶数 偶数 奇数 偶数 $ \rightarrow$ 奇数 奇数 \(\rightarrow\) 偶数 偶数 最后都变成偶数好像就是最优啊,…
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相邻的位置,更新长度为r - l - 1的最大值,感觉线段树结构体封装不错! 详细解释:http://blog.csdn.net/u010660276/article/details/46045777 其实还有其他解法,先掌握这种:) */ #include <cstdio> #include &l…
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:http://blog.csdn.net/u014357885/article/details/46044287 */ #include <cstdio> #include <algorithm> #include <cstring> #include <iostream…
题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <string> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN][MAXN]; int num[MAXN];…