题意:有一个长度为\(n\)的序列,你每次可以对序列重新排序,然后花费\(1\)使某个元素加减\(1\),多次操作后使得新序列满足\(a_{i}=c^i\),\(c\)是某个正整数,求最小花费. 题解:先排序,我们可以直接枚举\(c\),然后模拟维护一个最小值就好了. 代码: int n; int a[N]; int main() { //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); n=read(); for(int i=1;i<=n;…
题意:给你一个由\(0,1,?\)组成的字符串,你可以将\(?\)任意改成\(0\)或\(1\),问你操作后能否使得该字符串的任意长度为\(k\)的区间中的\(0\)和$1的个数相等. 题解:我们首先看前\(k\)个字符,那么对于区间\([2,k+1]\),如果要满足条件,\(s_{k+1}=s_{1}\)一定要成立,由此我们可以推导出,\(s_{i\ mod\ k}=s_{i}\),然后模拟就可以了,具体看代码. 代码: int t; int n,k; char s[N]; int cnt1,…
D. Concatenated Multiples You are given an array aa, consisting of nn positive integers. Let's call a concatenation of numbers xx and yy the number that is obtained by writing down numbers xx and yy one right after another without changing the order.…