题目
从官网得知即可
解题思路
我没有使用三重循环对两个进行比较 而是用pos1 和 pos2 对比较对象进行标注
其余的部分相对来说比较简单 自行查看代码即可
代码
#include <iostream>
#include <algorithm>
using namespace std;
int dp[1001][11];
int res[1001];
int n, m;
// 结果打印函数
void result_cout();
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
{
res[i] = -1;
}
for (int i = 0; i < n; i++)
{
int s = 0;
for (int j = 0; j < m; j++)
{
cin >> dp[i][j];
s += dp[i][j];
}
dp[i][m] = s; // 使用向量维数的和进行初步的筛查
}
// 两重循环 设置坐标表示比较的仓库
int pos1 = 0, pos2 = 0;
// 当前 比较对象
for (int i = 0; i < n * n; i++)
{
if (dp[pos1][m] >= dp[pos2][m])
{
}
else
{
// 对每位进行比较
bool flag = true;
for (int j = 0; j < m; j++)
{
if (dp[pos1][j] >= dp[pos2][j])
{
flag = false;
}
}
if (flag)
{
res[pos1] = pos2 + 1;
}
else
{
if (pos2 == n - 1)
{
res[pos1] = 0;
}
}
}
// 设置迭代起始
if (res[n - 1] != -1)
{
result_cout();
return 0;
}
if (pos2 == n - 1)
{
res[pos1]=0;
pos2 = 0;
if (pos1 == n - 1)
{
result_cout();
return 0;
}
else
{
pos1++;
}
}
else
{
pos2++;
if (res[pos1] != -1)
{
pos2 = 0; // 表示找到了上级仓库一定是最小的编号
pos1++;
}
}
}
return 0;
}
void result_cout()
{
for (int i = 0; i < n; i++)
{
cout << res[i] << endl;
}
}