0
点赞
收藏
分享

微信扫一扫

图像识别第十三届ICPC

陆公子521 2022-04-26 阅读 57
c++

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

如图所示,给你一个图像,图像内有一个由'*'画成的坐标轴,有一个'#'代表目标点。现在以二维矩阵的形式给你该图像,你能否求出'#'所在的位置的坐标是什么?

第一行输入两个正整数n,m(1≤n,m≤1000)n,m(1\leq n,m\leq 1000)n,m(1≤n,m≤1000)
其后n行,每行一个长度为m的字符串,图像矩阵A,矩阵内'*'表示坐标轴,'#'表示目标点,'.'表示空保证目标点唯一且不在坐标轴上。
输出两个整数x,y,代表目标点的坐标。

示例1

10 10
........*.
........*.
........*.
........*.
....#...*.
........*.
........*.
**********
........*.
........*.
-4 3

#include <iostream>
using namespace std;
const int N = 1000+10;
struct STR
{
	string s;
};
int main()
{
	int n,m;
	cin>>n>>m;
	STR str[N];
	getchar();
	for(int i = 0;i < n;i ++ )
	{
		string t;
		getline(cin,t);
		str[i].s=t;
	}
	int x=0,y=0;
	for(int i = 0;i < n;i ++ )
	{
		for(int j = 0;j < m;j ++ )
		{
			if(str[i].s[j]=='#')
			{
				x=i+1;
				y=j+1;
				break;
			}
		}
	}
	int x0=0,y0=0;
	for(int i = 0;i < n;i ++ )
	{
		for(int j = 0;j < m;j ++ )
		{
			if((str[i].s[j]=='*'&&str[i+1].s[j]=='*'&&str[i].s[j-1]=='*')||(str[i].s[j]=='*'&&str[i+1].s[j]=='*'&&str[i].s[j+1]=='*'))
			{
				x0=i+1;
				y0=j+1;
				break;
			}
			else if((str[i].s[j]=='*'&&str[i-1].s[j]=='*'&&str[i].s[j-1]=='*')||(str[i].s[j]=='*'&&str[i-1].s[j]=='*'&&str[i].s[j+1]=='*'))
			{
				x0=i+1;
				y0=j+1;
				break;
			}
		}
	}
	cout<<y-y0<<' '<<x0-x;
	return 0;
}
举报

相关推荐

0 条评论