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

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务