赞
踩
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); } }
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);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。