我觉得应该直接比较单价。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int x = in.nextInt();
if(b/3 < a){
int y = x %3;
int z = (x-y)/3;
int re = z*b + a;
System.out.println(re);
}else{
System.out.println(a*x);
}
}
} import java.util.*;
import java.io.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) throws IOException {
long a = ad(); // a元买1只
long b = ad(); // b元买3只
long x = ad(); // x只
// 如果3a>b,说明你卖的东西贵了
// ans = (x % 3) * a + (x / 3) * b;
long ans = 0;
// 9 + 1
if (a >= b) { // 用b买划算
if (x % 3 == 0) { // 特判 %1和%2的情况
ans = (x / 3) * b;
} else {
ans = (x / 3 + 1) * b;
}
} else if (3 * a < b) { // 用a划算
ans = x * a;
} else { // a和b自由组合
ans = (x % 3) * a + (x / 3) * b;
}
System.out.println(ans);
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StreamTokenizer st = new StreamTokenizer(br);
static long ad() throws IOException {
st.nextToken();
return (long) st.nval;
}
} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long a = scanner.nextLong(); // 1只竹鼠的价格
long b = scanner.nextLong(); // 3只竹鼠的价格
long x = scanner.nextLong(); // 需要的竹鼠数量
// 计算3只一组的单价是否比单只购买更划算
// 如果3只的价格比单买3只便宜,则优先考虑3只一组的购买方式
if (b < 3 * a) {
// 计算需要多少组3只
long groups = x / 3;
// 计算剩余不足3只的数量
long remainder = x % 3;
// 总花费 = 组数*每组价格 + 剩余数量的最小花费
// 剩余数量的花费可以选择单买,或者再买一组3只(可能更便宜)
long cost = groups * b + Math.min(remainder * a, b);
System.out.println(cost);
} else {
// 如果3只一组不划算,全部单买
System.out.println(x * a);
}
}
}
import java.util.*;
import java.io.*;
// 能买三只时,计算a,b两种策略买三只花费选最小的
// 不能买三只时,选取a策略购买和b策略最小值,选b时多买几只也没事儿,因为题目有至少
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] line = bf.readLine().split(" ");
long a = Integer.parseInt(line[0]);//a*3会超过int范围,所以a用long
int b = Integer.parseInt(line[1]);
int x = Integer.parseInt(line[2]);
long sumMin = 0;//花费用long
while (x >0) {
if (x >= 3) {
sumMin += Math.min(a * 3, b);
} else {
sumMin += Math.min(a*x, b);
}
x-=3;
}
System.out.println(sumMin);
}
} public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long a = in.nextLong();
long b = in.nextLong();
long x = in.nextLong();
if ( b / 3 < a) {
long cost = x % 3;
if (cost == 0) {
System.out.println((x / 3) * b);
} else if (cost * a < b){
System.out.println((x / 3) * b + cost * a);
}else {
System.out.println((x / 3) * b + b);
}
} else {
System.out.println(a * x);
}
}