• 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
    • 2
    • 3
    • 4

    样例输出 #1

    1 1
    
    • 1

    样例 #2

    样例输入 #2

    3 3
    *.*
    *..
    ...
    
    • 1
    • 2
    • 3
    • 4

    样例输出 #2

    2 3
    
    • 1

    分析

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

    代码

    #include
    
    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;
    		}
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
  • 相关阅读:
    033-使用UIManager设置组件外观界面,适应不同操作系统
    嵌入式-C语言关系运算符
    Pytorch入门实例
    微服务学习第三十二节
    如何在OneFlow中新增算子
    [centos]centos镜像ISO下载地址
    harbor网桥修复 产生了多个br-设备
    【谷粒商城 - k8s、devOps专栏】
    golang gorm——hook和session配置
    <react求和案例>react-redux基本使用与优化——Provider/mapDispatch
  • 原文地址:https://blog.csdn.net/m0_66603329/article/details/126858765