• 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
  • 相关阅读:
    DNS协议、ICMP协议、NAT技术
    2023最新SSM计算机毕业设计选题大全(附源码+LW)之java高校教室管理系统9y8cv
    二叉树最近的公共祖先[后序遍历与回溯模型的考察]
    怎么将视频转化为gif?
    递增删除图象
    unplugin-vue-components和unplugin-auto-import插件
    Deep Regression via Multi-Channel Multi-Modal Learning for Pneumonia Screening
    TLS/SSL(九) TLS1.2与TLS1.3中的ECDH协议
    机器学习前沿:改进自身缺陷,满足新战略
    BSN-DDC基础网络DDC SDK详细设计五:官方合约BSN-DDC-1155
  • 原文地址:https://blog.csdn.net/m0_66603329/article/details/126858765