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

相关推荐

07-23 14:04
东北大学 C++
既然这样,为什么不点击就送呢
牛马88号:因为你合适。但有很多笔试就挂了、通过了再排序的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
我的简历长这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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