B. Irreducible Anagrams【CF 1290B】】的更多相关文章

思路: 设tx为t类别字符的个数. ①对于长度小于2的t明显是"YES"②对于字符类别只有1个的t明显是"YES"③对于字符类别有2个的t,如左上图:如果str[l] != str[r],那么我们构造的t也应该是str[l] != str[r],且s字串和t的str[l]和str[r]是相反的,即如图所示.继续,如图构造,即bbb..a...a这样,我们发现第一个图片除去str[l] = a和str[r]=b之外,中间怎么放置字符,都会出现"Irreduc…
[题目描述] 有一张N,M<=10^12的表格,i行j列的元素是gcd(i,j) 读入一个长度不超过10^4,元素不超过10^12的序列a[1..k],问是否在某一行中出现过 [题解] 要保证gcd(x,y)=a[i],显然x=lcm(a[1],a[2]……a[k]) 然后y%a[1]=0,即(y+i-1)%a[i]=0 即y%a[1]=0 y%a[2]=-1 …… y%a[n]=-(n-1) 这就转化为了中国剩余定理 求出y之后,只需验证gcd(x,y+i-1)=a[i]即可 /*******…
[题目描述] Bike是一位机智的少年,非常喜欢数学.他受到142857的启发,发明了一种叫做“循环数”的数. 如你所见,142857是一个神奇的数字,因为它的所有循环排列能由它乘以1,2,...,6(1到它的长度)得到.循环排列意味着将该数的一些数位从尾部挪到前面.例如,12345的循环排列包括:12345,51234,45123,34512,23451.值得一提的是,允许出现前导零.因此4500123和0123450都是0012345的循环排列.你可以看到142857满足条件的原因.以下六个…
题意 给你一棵 \(n\) 个点的树,每个节点有两个权值 \(a_i,b_i\). 从一个点 \(u\) 可以跳到以其为根的子树内的任意一点 \(v\)(不能跳到 \(u\) 自己),代价是 \(a_u\times b_v\). 求每个点跳到任意一个叶子的最小代价. \(n\le 10^5, -10^5\le a_i,b_i\le 10^5\) 题解 暴力 考虑暴力 \(dp\),设 \(dp_i\) 表示从叶子跳到 \(i\) 号点的最小代价. 则有转移 \(dp_u = \min\{a_u\…
A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept…
E. Present for Vitalik the Philatelist time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Vitalik the philatelist has a birthday today! As he is a regular customer in a stamp store called 'Ro…
time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries and a multiset A, initi…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today an outstanding event is going to happen in the forest - hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your hel…