题解 | 清楚姐姐买竹鼠

清楚姐姐买竹鼠

https://www.nowcoder.com/practice/816dfe69f83042108cf8c74531a94a35

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
		long a, b, x;
		a = scanner.nextInt();
		b = scanner.nextInt();
		x = scanner.nextInt();
		long c;
		long cost1 = 0;
		long cost2 = 0;
		long cost3 = 0;
		//全用a买
		cost1=a*x;
		//用b买k组,剩余用a补
		cost2=x/3*b+x%3*a;
		//全用b组买,可能多买,也可能更便宜
		cost3=(x/3+1)*b;
		System.out.println(Math.min(Math.min(cost1, cost2), cost3));
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务