Fork me on GitHub

牛客网编程练习之网易2017校招题:解救小易

   image

image

 

思路:

如果使用遍历的话需要遍历每一个点然后再比较,这样也许可以通过一些样例,但是很容易就是TLE了,所以应该还有更好的办法。

走格子这种问题,如果不能斜着走的话,那么从(1, 1)走到任意一个位置(x, y)都需要在x轴走上(x-1)步,在y轴走上(y-1)步,加起来就是x+y-2步,所以这道题就变成了简单的比大小。

 

AC代码:

import java.util.Scanner;
 
/**
 * @author CC11001100
 */
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
        int[] _1 = new int[sc.nextInt()];
 
        for(int i=0; i<_1.length; i++){
            _1[i] = sc.nextInt();
        }
 
        int min = Integer.MAX_VALUE;
        for (int i : _1) {
            min = Math.min(min, i + sc.nextInt());
        }
 
        System.out.println(min - 2);
 
    }
 
}

 

题目来源: https://www.nowcoder.com/practice/cd763d8541fc4243b8d3b967bb6d6b6a?tpId=85&tqId=29841&tPage=1&rp=1&ru=/ta/2017test&qru=/ta/2017test/question-ranking

 

.

posted @ 2017-12-10 17:38  CC11001100  阅读(189)  评论(0编辑  收藏  举报