9.20腾讯笔试(第二题,100%)

//房子涂色,相邻的房子不能同色,求代价最小的涂法
import java.util.Scanner;

/**
 * Created by lenovo on 2019/9/20.
 */
public class two {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
        int n = read.nextInt();
        int[] cost = new int[3];
        int i = 0;
        int[] now = new int[3];
        while(i < n){
            if(i == 0){
                cost[0] = read.nextInt();
                cost[1] = read.nextInt();
                cost[2] = read.nextInt();
            }else{
                now[0] = read.nextInt();//r
                now[1] = read.nextInt();//g
                now[2] = read.nextInt();//b
                now[0] = Math.min(now[0] + cost[1], now[0] + cost[2]);
                now[1] = Math.min(now[1] + cost[0], now[1] + cost[2]);
                now[2] = Math.min(now[2] + cost[0], now[2] + cost[1]);

                cost[0] = now[0];
                cost[1] = now[1];
                cost[2] = now[2];
            }
            i++;
        }
        int min;
        min = cost[0] < cost[1] ?  cost[0] : cost[1];
        min = min < cost[2] ? min : cost[2];
        System.out.println(min);
    }
}

#腾讯##笔试题目#
全部评论
这个是那道题的,方便放一下题目吗
点赞 回复 分享
发布于 2019-09-20 22:35

相关推荐

程序员牛肉:主要是因为小厂的资金本来就很吃紧,所以更喜欢有实习经历的同学。来了就能上手。 而大厂因为钱多,实习生一天三四百的就不算事。所以愿意培养你,在面试的时候也就不在乎你有没有实习(除非是同级别大厂的实习。) 按照你的简历来看,同质化太严重了。项目也很烂大街。 要么换项目,要么考研。 你现在选择工作的话,前景不是很好了。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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