# [编程题]抛小球

100,90,80,70

package li.gh;

import java.util.Scanner;

public class dsf {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int d = in.nextInt();

System.out.println(fun(a));
System.out.println(fun(b));
System.out.println(fun(c));
System.out.println(fun(d));
System.out.println(fun(a) + fun(b) + fun(c) + fun(d));

}

public static int fun(int a) {
if (a == 1)
return 2;
else {
if (a % 2 == 0) {
// return 1;
// if(a==0) return 0;
return fun(a / 2) + a;
} else {
return fun((a + 1) / 2) + a;
}
}

}

}


package li.gh;

import java.util.Scanner;

public class dsf {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int d = in.nextInt();

System.out.println(getDir(a));
System.out.println(getDir(b));
System.out.println(getDir(c));
System.out.println(getDir(d));
System.out.println(getDir(a) + getDir(b) + getDir(c) + getDir(d));
}

public static int getDir(int n) {
int s = n;
while (n > 0) {
if (n % 2 == 0) {
s += n;
} else {
s += ((n + 1) / 2) * 2;
}
n /= 2;
}
return s;
}

}


• 本文已收录于以下专栏：

举报原因： 您举报文章：[编程题]抛小球 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)