P8739 [蓝桥杯 2020 国 C] 重复字符串
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int k = sc.nextInt();sc.nextLine();char[] c = sc.nextLine().toCharArray();int cl = c.length;if(cl%k!=0) {System.out.println("-1");return ;}int zl = cl/k;//子串长度int ans = 0;for(int i=0;i<zl;i++) {Map<Character,Integer> map = new HashMap<>();int MAX = Integer.MIN_VALUE;for(int j=i;j<cl;j+=zl) {map.put(c[j],map.getOrDefault(c[j],0)+1);MAX = Math.max(MAX,map.get(c[j]));}ans+=k-MAX;}System.out.println(ans);}
}
P8627 [蓝桥杯 2015 省 A] 饮料换购
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int sum = n;while(n>2) {int t = n/3;sum+=t;n = t+n%3;}System.out.println(sum);}
}