Salut ;
je cherche à récupérer toutes les lignes non dominantes d'une matrice.
par exemple j'ai une matrice (A ) tel que le nombre de ligne = 9 , le nombre de colonnes = 2 .
A = [[-1, 7], [ 3, 1], [ 2, -5], [ 7, 6], [0,1] ,[4,-1] ,[8,7] ,[-2,6] ,[4,6] ]. Les solutions qui on veut récupérées : [2 , -5] [0 , 1] [-2 , 6].
mais lorsque j'applique le programme en dessous je trouve [3 , 1] [2 , -5] [0 , 1] [-2 , 6].
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 double mat[][] = { { -1, 7}, { 3, 1}, { 2 , -5}, {7 ,6}, {4 ,-1}, {0, 1}, {8 , 7}, {-2 , 6}, { 4 , 6 } }; double a=-1 ; double a1 = 7 ; for (int i = 0; i < mat.length ; i++) { //for (int j = 0; j < 1; j++) { int j=0; if (((mat[i][j] < a && mat[i][j+1] > a1))|| ((mat[i][j] > a && mat[i][j+1] < a1)) || ((mat[i][j] < a && mat[i][j+1] < a1))) { a = mat[i][j]; a1 = mat[i][j+1]; System.out.print("["+ a + " , "+ a1+"]"); } } }
Partager