problem1 link 枚举指数,然后判断是不是素数即可. problem2 link 令$f[len][a][b][r]$(r=0或者1)表示子串$init[a,a+len-1]$匹配$goal[b,b+len-1]$,翻转了$r$次的最小代价. problem3 link 答案的公式很容易推导,为$n*\sum_{i=n-k+1}^{n}\frac{1}{i}$. 调和级数为$H(n)=\sum_{i=1}^{n}\frac{1}{i}$ 所以答案为$n*(H(n)-H(n-k))$ 由…
problem1 link 首先枚举长度$L$.然后计算每一段长度$L$的差值最大公约数,然后差值除以最大公约数的结果可以作为当前段的关键字.然后不同段就可以比较他们的关键字,一样就是可以转化的. problem2 link 对于那些一定要换的,把它们的places和cutoff拿出来,排个序.设它们为$p_{1},p_{2},..,p_{k},c_{1},c_{2},..,c_{k},$.最优的策略一定是从小到大挨个匹配. 如果到了某个位置不能匹配,比如$t$.那么需要从那些不需要交换的组里面…
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x)=\sum_{i=1}^{x}g(i)$,那么答案为$h(R)-h(L-1)$.对于$h(x)$: (1)如果$x\leq K$,那么$h(x)=0$ (2)否则对于$[K+1,x]$之间的所有偶数来说,对答案的贡献为$even+h(\frac{x}{2})-h(\frac{K}{2})$,其中$e…
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle with the following properties: The coordinates of each vertex are integers between 0 and 3000, inclusive. The perimeter of the triangle must be exactly…
Problem Statement The Happy Letter game is played as follows: At the beginning, several players enter the field. Each player has a lowercase English letter on their back. The game is played in turns. In each turn, you select two players with dif…