问题描述
西西艾弗岛共有 n个仓库,依次编号 1⋯n。每个仓库均一个 m 维向量的位置编码,用来表示仓库间的物流运转关系。
思路:
其实就三个for循环去解决,首先第一个for循环,就是到谁就找到其所对应的仓库 1到n
第二个for循环就是去找到除了该行之外的其他行 也是1到n
第三个for循环就就是对于两个行之间的各个维度的比较(因为比较乱,所以单独作为函数,调用)
代码:100分
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int arr[1000][10];
int n, m;
bool slove(int i, int j) {
int a;
int count = 0;
for (a = 0; a < m; a++) {
if (arr[i][a] < arr[j][a]) {
count++;
}
}
return (count == m) ? true : false;
}
int main() {
cin >> n >> m;
int i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cin >> arr[i][j];
}
}
for (i = 0; i < n; i++) {
int b = 0;
for (j = 0; j < n; j++) {
if (slove(i, j)) {
b = j;
break;
}
}
cout << b << endl;
}
}