Rescue Xiaoyi

Topic description

There is a 1000*1000 grass field, and Xiaoyi initially stands at (1,1) (the upper leftmost position). Xiaoyi will move horizontally or vertically to the adjacent grass to graze every second (Xiaoyi will not go out of the border). The big villain Chaochao wants to catch the cute Xiaoyi, and he has n traps in his hand. The i-th trap is placed at the position where the abscissa is xi  and the ordinate is y i  . Once Xiaoyi walks into a trap, he will be caught by Chaochao. In order to rescue Xiaoyi, you need to know at least how many seconds Xiaoyi may fall into a trap, so as to rescue Xiaoyi in advance.

Enter description:

The first line is an integer n (n ≤ 1000), indicating that the super super has a total of n traps.
The second row has n integers x
i
, representing the abscissa of the i-th trap
The third row has n integers y
i
, representing the ordinate of the i-th trap
Make sure that the coordinates are all within the grass range.

Output description:

Output an integer, indicating how many seconds Xiaoyi may fall into the Chaochao trap at least
Example 1

enter

3
4 6 8
1 2 1

output

3
1  import java.util.Scanner;
 2  
3  /** 
4  * 
 5  * 
 6  * Rescue Xiaoyi 
 7  * Calculate the nearest trap
 8  * @author Dell
 9  *
 10   */ 
11  public  class Main {
 12      
13  public  static  void main( String[] args) {
 14      Scanner sc = new Scanner(System.in);
 15      int n = sc.nextInt();
 16      int [] x = new  int [n];
17     int[] y= new int[n]; 
18     for (int i = 0; i < x.length; i++) {
19         x[i] = sc.nextInt();
20     }
21     for (int i = 0; i < y.length; i++) {
22         y[i] = sc.nextInt();
23     }
24     int min = Integer.MAX_VALUE;
25     for (int i = 0; i < n; i++) {
26         if (x[i]-1+y[i]-1<min) {
27             min =x[i]-1+y[i]-1;
28         }
29     }
30     System.out.println(min);
31 }
32 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325132639&siteId=291194637