苏轼西湖寻宝:破解藏宝图的秘密
苏轼在西湖钓鱼时遇到了一位正在钓鱼的老叟,可是他发现老叟的钓鱼竿上并没有钩子,苏轼感到非常奇怪,正当他想问老叟的时候,老叟丢给了他一张图纸,说:'传闻此湖中有一个宝藏,今日见你有缘,就把这藏宝图赠与你罢',说完扬长而去。
苏轼打开藏宝图,上面写着'东西最浅,且南北最深处',意思就是埋藏宝物的点在所在的同一水平线上水深是最浅的,同时在所在的同一竖直线上是最深的,后面是西湖的水深地形图。
你可否帮助苏轼找到此宝藏呢?
输入格式
只有一组输入
第一行输入n,m(1<=n,m<=100),分别表示西湖的南北方向长度和东西方向长度
接下来n行每行输入m个数据,表示各坐标的湖水水深
保证每组数据有且只有一个这样的点,且每处水深不同
输出格式
输出宝藏坐标
样例
输入
3 3
1 2 3
4 5 6
7 8 9
输出
(3,1)
输入
3 3
1 2 3
7 8 9
5 4 6
输出
(2,1)
输入
3 3
9 10 3
8 12 7
11 4 5
输出
(2,3)
输入
4 4
24 31 52 61
20 75 11 32
22 72 44 65
12 5 108 33
输出
(1,1)
代码实现
你可以使用C++编写一个程序来解决这个问题。下面是一个可能的解决方案:
#include <iostream>
#include <vector>
#include <utility>
int main() {
int n, m;
std::cin >> n >> m;
std::vector<std::vector<int>> depths(n, std::vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
std::cin >> depths[i][j];
}
}
int shallowest = depths[0][0];
int deepest = depths[0][0];
std::pair<int, int> treasure_location;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (depths[i][j] < shallowest) {
shallowest = depths[i][j];
treasure_location.first = i + 1;
}
if (depths[i][j] > deepest) {
deepest = depths[i][j];
treasure_location.second = j + 1;
}
}
}
std::cout << '(' << treasure_location.first << ',' << treasure_location.second << ')' << std::endl;
return 0;
}
这个程序首先读取输入的n和m,表示西湖的南北方向长度和东西方向长度。然后,使用一个二维向量depths来存储各坐标的湖水水深。
接下来,程序遍历整个depths向量,找到最浅的水深和最深的水深,并记录它们所在的坐标。最后,输出宝藏的坐标。
希望以上信息对你有帮助!如果你对其他方面有任何问题,请随时问我。
原文地址: https://www.cveoy.top/t/topic/bhvI 著作权归作者所有。请勿转载和采集!