Topic Background Background
The Fuhrer is angry!!
Title Description DescriptionSince the Germans tore up the treaty to attack the Soviet Union, Stalin has been sickly unhappy, and recently someone reported that the enemy in a mountainous area buried a lot of landmines, in order to ensure that no injury, the German army in two-dimensional coordinates.
If the coordinate system is constructed according to the origin of each known mine location, there may be mines at the intersection of the axes of the two mines, and you are now asked to calculate the maximum number of mines possible.
For example, if:
#################
####$############
#################
###########$#####
#################
The pound sign indicates an unknown area, and the dollar number indicates a known mine, if two thunder is known, then:
#################
####$######*#####
#################
####*######$#####
#################
The output may have mined areas such as *
Now you need to find all possible minefields based on the above rules, identify them as *, and then output
input/output format input/output
Input Format:
Enter two numbers x, Y, indicating the matrix is long (horizontal) and wide (longitudinal), the second line is a matrix that contains # and $
output Format:
Outputs a matrix that indicates a known and probable minefield, and then outputs a number after the matrix is lost, indicating the presence of most mines
input and Output sample sample Input/output
sample Test point # #
Input Sample:
20 6
####################
####$###############
####################
###########$########
####################
##############$#####
Sample output:
####################
####$######*##*#####
####################
####*######$##*#####
####################
####*######*##$#####
9
Idea: This question, very simple, really is water problem ah ...
From the sample it is not difficult to analyze, each ' * ' coordinates is each ' $ ' in addition to its own ordinate with the other ' $ ' horizontal axis.
For example, the three ' $ ' coordinates given in the sample are: ① (5,5) ② (12,3) ③ (15,1)
The other six ' * ' coordinates are: ① (5,1) ② (5,3) ③ (12,1) ④ (12,5) ⑤ (15,3) ⑥ (15,5)
It is not difficult to find that the ' * ' coordinates are ' $ ' ordinate with the horizontal axis of the other $ '
Then this problem is good to do, on the code!
The code is as follows:
1#include <stdio.h>2 intMain ()3 {4 Chara[ -][ -];5 intb[ -][2],ans=0;//Storage coordinates6 intn,m,i,j,k=0;7scanf"%d%d",&n,&m);8 GetChar ();9 for(i=0; i<m;i++)//Enter MapTen { One gets (A[i]); A } - for(i=0; i<m;i++) - { the for(j=0; j<n;j++) - { - if(a[i][j]=='$')//storing known mine coordinates - { +b[k][0]=i;//Ordinate -b[k][1]=j;//Horizontal Axis +k++; A } at } - } - for(i=0; i<k;i++) - { - for(j=0; j<k;j++) - { in if(i!=j) - { toa[b[i][0]][b[j][1]]='*';//Mark as mine +ans++;//Number of Mines + + - } the } * } $ for(i=0; i<m;i++)Panax Notoginseng { -printf"%s\n", A[i]); the } +printf"%d\n", ans+k);//previous mines plus statistics on mines A return 0; the}
Rokua-10 March Soviet Union-[No more pits] "World War 2" World War II series 2: Scorching