爱奇艺2018秋季校招java工程师(第二场)
字符串价值-AC(最笨的办法居然AC)
package iQIYI.QiuZhao2017_2.ValueOfString;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
/**
* Created by tzy on 2017/10/14.
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in );
while (sc.hasNext()) {
String str = sc.nextLine();
int num = Integer.parseInt(sc.nextLine());
List<Temp> list = new LinkedList<Temp>();
char[] chars = new char[127];
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
chars[ch]++;
}
for (int i = 0; i < chars.length; i++) {
if (chars[i] != 0) {
Temp t = new Temp(String.valueOf(i).charAt(0), chars[i]);
list.add(t);
}
}
Collections.sort(list);
while (num > 0) {
list.get(0).count--;
num--;
Collections.sort(list);
}
int res = 0;
for (int i = 0; i < list.size(); i++) {
res += list.get(i).getCount() * list.get(i).getCount();
}
System.out.println(res);
}
}
}
class Temp implements Comparable<Temp> {
Character ch;
int count;
public int compareTo(Temp o) {
return o.count - this.count;
}
public char getCh() {
return ch;
}
public void setCh(char ch) {
this.ch = ch;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public Temp(char ch, int count) {
this.ch = ch;
this.count = count;
}
}
第二题博弈论~~不会
第三题~~~就是考大数类,妈的又一次载在了大数类,上次滴滴就是,我还能说啥~~没有提交。不过感觉没有错
package iQIYI.QiuZhao2017_2.sdf;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
/**
* Created by tzy on 2017/10/14.
*/
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
while (scanner.hasNext()){
int n=scanner.nextInt();
int m=scanner.nextInt();
System.out.println(getExp(n,m));
}
}
public static BigDecimal getExp(int n,int m){
BigInteger total=combination(m+n,2);
BigInteger num=combination(m,2);
int temp=n*m;
BigInteger num1=new BigInteger(String.valueOf(temp));
BigInteger sum=num.add(num1);
BigDecimal total0=new BigDecimal(total);
BigDecimal sum0=new BigDecimal(sum);
return total0.divide(sum0,1,BigDecimal.ROUND_UP);
}
public static BigInteger combination(int n, int m) {
BigInteger big_m=factorial(m);
BigInteger big_n=factorial(n);
BigInteger big_n_m=factorial(n-m);
BigInteger result=big_n.divide(big_n_m);
result=result.divide(big_m);
return (n >= m) ? result : new BigInteger("0");
}
private static BigInteger factorial(int n) {
BigInteger result=new BigInteger("1");
for (int i = 1; i <=n ; i++) {
result=result.multiply(new BigInteger(String.valueOf(i)));
}
return result;
}
}
#爱奇艺#
