1. 跳舞机

alt

public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int score=0;//默认分数为0
        while(sc.hasNext()){
            String a=sc.next();
            String b=sc.next();
            char[] chars1=a.toCharArray();
            char[] chars2=b.toCharArray();
            int l=0;
            int r=a.length();
            while(l<r){
                if(chars1[l]==chars2[l]){
                    score+=20;
                    l++;
                }else{
                    score=score>=10?score-10:0;
                    l++;
                }
            }
            System.out.println(score);
        }
    }

2. 元素平衡

alt

思路

网上方法

public class EleBalance {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()){
            long[] eles = new long[4];
            int sum = 0;
            for (int i = 0; i < 4; i++) {
                eles[i] = in.nextLong();
                sum += eles[i];
            }
            long avl = sum/4;
            long l = 0,r = 0;   //l累加比avl小的,r累加比avl大的
            for (int i = 0; i < 4; i++) {
                long sub = eles[i]-avl;
                if(sub<0)
                    l -= sub;   //由于sub小于0,所以用-=
                else if(sub>0)
                    r += sub;
            }
            long x = 2*l-r;     //比较用R去比L,够不够
            if (x<=0)
                System.out.println(avl*4);  //小于等于0说明是够的
            else
      System.out.println((long)(avl-Math.ceil(((double)x)/4))*4);             
                //大于0说明不够,那么输出avl-差值除以4向上取整
        }
    }
}