Created
August 29, 2013 07:34
-
-
Save w00lf/6375160 to your computer and use it in GitHub Desktop.
****************Седловые точки****************
Найдите количество седловых точек заданной матрицы. Входные данные Входной файл INPUT.TXT в первой строке содержит целые числа N и M (1 <= N, M <= 750). Далее следуют N строк по M чисел в каждой. Элементы матрицы - целые числа, не превосходящие 1000 по абсолютной величине. Выходные данные В выходной…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class Main{ | |
public static void main(String[] argv) throws IOException,Exception{ | |
new Main().run(); | |
} | |
PrintWriter pw; | |
public static StreamTokenizer sc ; | |
public static int nextInt() throws Exception{ | |
sc.nextToken(); | |
return (int)sc.nval; | |
} | |
public void run() throws IOException,Exception{ | |
sc = new StreamTokenizer(new BufferedReader(new FileReader("input.txt"))); | |
Boolean[][] minimums = new Boolean[nextInt()][nextInt()]; | |
Boolean[][] maximums = new Boolean[minimums.length][minimums[0].length]; | |
int[] maximum_columns = new int[minimums[0].length]; | |
int current = 0; | |
int minimum = 2100; | |
for (int i = 0; i < minimums.length; i++) { | |
for (int j = 0; j < minimums[0].length; j++) { | |
current = nextInt(); | |
if (i == 0) { | |
maximum_columns[j] = current; | |
maximums[i][j] = true; | |
} else { | |
if (current == maximum_columns[j]) { | |
maximums[i][j] = true; | |
} | |
if (current > maximum_columns[j]) { | |
for (int k = 0; k < minimums.length; k++) { | |
maximums[k][j] = false; | |
} | |
maximums[i][j] = true; | |
maximum_columns[j] = current; | |
} | |
} | |
if (minimum == current) { | |
minimums[i][j] = true; | |
} | |
if (minimum > current) { | |
for (int k = 0; k < minimums[0].length; k++) { | |
minimums[i][k] = false; | |
} | |
minimums[i][j] = true; | |
minimum = current; | |
} | |
} | |
minimum = 2100; | |
} | |
int result = 0; | |
for (int i = 0; i < minimums.length; i++) { | |
for (int j = 0; j < minimums[0].length; j++) { | |
if (minimums[i][j] != null && maximums[i][j] != null && minimums[i][j] == true && maximums[i][j] == true) { | |
result += 1; | |
} | |
} | |
} | |
pw = new PrintWriter(new File("output.txt")); | |
pw.print(result); | |
pw.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment