CF181A Series of Crimes

Series of Crimes

题面翻译

给出一幅 n n n m m m列的图,其中有3个*,求另一个*的位置使得这4个*构成一个矩形。

题目描述

The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.

The Berland capital’s map is represented by an $ n×m $ rectangular table. Each cell of the table on the map represents some districts of the capital.

The capital’s main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map.

Polycarpus is good at deduction but he’s hopeless at math. So he asked you to find the district where the fourth robbery will be committed.

输入格式

The first line contains two space-separated integers $ n $ and $ m $ ( $ 2<=n,m<=100 $ ) — the number of rows and columns in the table, correspondingly.

Each of the next $ n $ lines contains $ m $ characters — the description of the capital’s map. Each character can either be a “.” (dot), or an “*” (asterisk). A character equals “*” if the corresponding district has been robbed. Otherwise, it equals “.”.

It is guaranteed that the map has exactly three characters “*” and we can always find the fourth district that meets the problem requirements.

输出格式

Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.

样例 #1

样例输入 #1

3 2
.*
..
**

样例输出 #1

1 1

样例 #2

样例输入 #2

3 3
*.*
*..
...

样例输出 #2

2 3

分析

把每行每列的" * “的个数算出来,在查找一下只有1个” * “的行的位置与只有1个” * "的列的位置即可。

代码

#include<bits/stdc++.h>

using namespace std;

string s[10000];

int a[10000],b[10000];

int main()
{
	int n,m;
	
	cin>>n>>m;
	
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
	}
	
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(s[i][j]=='*')
			{
				a[i]++;
				
				b[j]++;
			}
		}	
	}
	
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1)
		{
			cout<<i<<" ";
			
			break;
		}
	}
	
	for(int j=0;j<m;j++)
	{
		if(b[j]==1)
		{
			cout<<j+1;
			
			break;
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

harmis_yz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值