Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- /**
- *
- * @author Maciek
- */
- public class JavaApplication1 {
- public static void Search(int data[][], int total, int minValue, int n, int m, int locationX, int locationY, int prevDepth)
- {
- if (data[locationY][ locationX] >= minValue && (
- (prevDepth < data[locationY][ locationX] && data[locationY][ locationX] < (prevDepth + 5) && data[locationY][ locationX] - prevDepth < 5) ||
- (prevDepth > data[locationY][ locationX] && data[locationY][ locationX] < (prevDepth + 5) && (prevDepth - data[locationY][ locationX]) < 5) ||
- data[locationY][ locationX] == prevDepth))
- {
- if (data[locationY][ locationX] - 5 >= minValue)
- {
- total += 5;
- }
- else
- {
- total += (data[locationY][ locationX] - minValue) + 1;
- }
- System.out.println(total);
- int prev_depth = data[locationY][ locationX];
- data[locationY][ locationX] = 10000;
- if ((locationY - 1) >= 0)
- {
- if (locationX + 1 < m && data[locationY - 1][ locationX + 1] != 10000)
- {
- Search( data, total, minValue, n, m, locationX + 1, locationY - 1, prev_depth);
- }
- if (locationX - 1 >= 0 && data[locationY - 1][ locationX - 1] != 10000)
- {
- Search( data, total, minValue, n, m, locationX - 1, locationY - 1, prev_depth);
- }
- if (data[locationY - 1][ locationX] != 10000)
- {
- Search( data, total, minValue, n, m, locationX, locationY - 1, prev_depth);
- }
- }
- if (locationY + 1 < n)
- {
- if (locationX + 1 < m && data[locationY + 1][ locationX + 1] != 10000)
- {
- Search( data, total, minValue, n, m, locationX + 1, locationY + 1, prev_depth);
- }
- if (locationX - 1 >= 0 && data[locationY + 1][ locationX - 1] != 10000)
- {
- Search( data, total, minValue, n, m, locationX - 1, locationY + 1, prev_depth);
- }
- if (data[locationY + 1][ locationX] != 10000)
- {
- Search( data, total, minValue, n, m, locationX, locationY + 1, prev_depth);
- }
- }
- if (locationX + 1 < m && data[locationY][ locationX + 1] != 10000)
- {
- Search( data, total, minValue, n, m, locationX + 1, locationY, prev_depth);
- }
- if (locationX - 1 >= 0 && data[locationY][ locationX - 1] != 10000)
- {
- Search( data, total, minValue, n, m, locationX - 1, locationY, prev_depth);
- }
- }
- }
- public static void main(String[] args) throws FileNotFoundException {
- Scanner sr = new Scanner(new File("in4.txt"));
- int total = 0;
- int n;
- int m;
- n = sr.nextInt();
- m = sr.nextInt();
- int[][] data = new int[n][m];
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- data[i][j] = sr.nextInt();
- }
- }
- int locationX ;
- int locationY ;
- locationX=sr.nextInt();
- locationY=sr.nextInt();
- int minValue =data[locationY - 1][ locationX - 1];
- Search( data, total, minValue, n, m, locationX - 1, locationY-1, data[locationY - 1][ locationX - 1]);
- System.out.println(total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement