10279 - Mine Sweeper

Moderator: Board moderators

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
If you have a lot of free time - you may try to send your personal access to do this job to judges

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:

Re: the end to the WA mystery of 10279 Minesweeper

stcheung wrote:Make sure you know it's a multiple input problem [...]
Hope this would end the WA mystery of this simple problem.
Thank a lot. I lost my source some time. I have it right now, did some modifications and got AC.
Not AC yet AC at last
Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

10279 - Minesweeper again - help

I don't get it... what is the meaning by this :

"If a mine has been touched, all positions with a mine should contain an asterisk. All other positions should contain a period."

Is that mean if a mine has been touched, we only have to output the map contains asteriks and periods ... ????

code :

Code: Select all

``````#include <stdio.h>

char input[10][10] , click[10][10] , output[10][10] ;
int NumOfCase , grid ;

char process ( void ) ;

int main ( void )
{
int i ;

/*  freopen ( "10279.in" , "r" , stdin ) ;
freopen ( "10279.out" , "w" , stdout ) ;*/

scanf ( "%i" , &NumOfCase ) ;

while ( NumOfCase -- )
{
scanf ( "%i" , &grid ) ;

for ( i = 0 ; i < grid ; i ++ )
scanf ( "%s" , input[i] ) ;

for ( i = 0 ; i < grid ; i ++ )
scanf ( "%s" , click[i] ) ;

if ( process ( ) )
{
for ( i = 0 ; i < grid ; i ++ )
printf ( "%s\n" , output[i] ) ;
}
else
{
for ( i = 0 ; i < grid ; i ++ )
printf ( "%s\n" , input[i] ) ;
}

printf ( "\n" ) ;
}

return 0 ;
}

char process ( void )
{
int i , j , counter ;

for ( i = 0 ; i < grid ; i ++ )
{
for ( j = 0 ; j < grid ; j ++ )
output[i][j] = '.' ;

output[i][j] = 0 ;
}

for ( i = 0 ; i < grid ; i ++ )
for ( j = 0 ; j < grid ; j ++ )
{
if ( click[i][j] == 'x' )
{
if ( input[i][j] == '*' )
return 0 ;

counter = 0 ;

if ( input[i-1][j-1] == '*' && i > 0 && j > 0 )
counter ++ ;
if ( input[i-1][j] == '*' && i > 0 )
counter ++ ;
if ( input[i-1][j+1] == '*' && i > 0 && j < grid - 1 )
counter ++ ;
if ( input[i][j-1] == '*' && j > 0 )
counter ++ ;
if ( input[i][j+1] == '*' && j < grid - 1 )
counter ++ ;
if ( input[i+1][j-1] == '*' && i < grid - 1 && j > 0 )
counter ++ ;
if ( input[i+1][j] == '*' && i < grid - 1 )
counter ++ ;
if ( input[i+1][j+1] == '*' && i < grid - 1 && j < grid - 1 )
counter ++ ;

output[i][j] = counter + '0' ;
}
}

return 1 ;
}
``````
the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Contact:
to almost human:
Is that mean if a mine has been touched, we only have to output the map contains asteriks and periods ... ????
nop. the problem statement says:
Your output should represent the board, with each position filled in appropriately. Positions that have been touched and do not contain a mine should contain an integer between 0 and 8. If a mine has been touched, all positions with a mine should contain an asterisk. All other positions should contain a period.
here All other positions means all untouched positions that have no mines.
if any mine(s) has been touched then show all mines with asterisks and other unmined touched position with number and rest untouched positions with a period.
input:

Code: Select all

``````8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxxxxxxx
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...``````
output:

Code: Select all

``````001**22*
0013..*.
0001*...
00011...
00001...
00123*..
001**.*.
00123*..``````
tell us if you still got problem.
btw. this was discussed in previous board topics.
thanks.
Istiaque Ahmed [the LA-Z-BOy]
Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm
I'd changed my code, but it still got Wrong Answer ... but thanks for your help...

any suggestion ... ?

Code: Select all

``````#include <stdio.h>

char input[10][10] , click[10][10] , output[10][10] ;
int NumOfCase , grid ;

void process ( void ) ;

int main ( void )
{
int i ;

/*  freopen ( "10279.in" , "r" , stdin ) ;
freopen ( "10279.out" , "w" , stdout ) ;*/

scanf ( "%i" , &NumOfCase ) ;

while ( NumOfCase -- )
{
scanf ( "%i" , &grid ) ;

for ( i = 0 ; i < grid ; i ++ )
scanf ( "%s" , input[i] ) ;

for ( i = 0 ; i < grid ; i ++ )
scanf ( "%s" , click[i] ) ;

process ( ) ;

for ( i = 0 ; i < grid ; i ++ )
printf ( "%s\n" , output[i] ) ;

if ( NumOfCase ) printf ( "\n" ) ;
}

return 0 ;
}

void process ( void )
{
int i , j , k , l , counter ;
char kaboom = 0 ;

for ( i = 0 ; i < grid ; i ++ )
{
for ( j = 0 ; j < grid ; j ++ )
output[i][j] = '.' ;

output[i][j] = 0 ;
}

for ( i = 0 ; i < grid ; i ++ )
for ( j = 0 ; j < grid ; j ++ )
{
if ( click[i][j] == 'x' )
{
if ( input[i][j] == '*' )
{
if ( kaboom == 0 )
{
kaboom = 1 ;

for ( k = 0 ; k < grid ; k ++ )
for ( l = 0 ; l < grid ; l ++ )
{
if ( input[k][l] == '*' )
output[k][l] = '*' ;
}
}
}
else
{
counter = 0 ;

if ( input[i-1][j-1] == '*' && i > 0 && j > 0 )
counter ++ ;
if ( input[i-1][j] == '*' && i > 0 )
counter ++ ;
if ( input[i-1][j+1] == '*' && i > 0 && j < grid - 1 )
counter ++ ;
if ( input[i][j-1] == '*' && j > 0 )
counter ++ ;
if ( input[i][j+1] == '*' && j < grid - 1 )
counter ++ ;
if ( input[i+1][j-1] == '*' && i < grid - 1 && j > 0 )
counter ++ ;
if ( input[i+1][j] == '*' && i < grid - 1 )
counter ++ ;
if ( input[i+1][j+1] == '*' && i < grid - 1 && j < grid - 1 )
counter ++ ;

output[i][j] = counter + '0' ;
}
}
}
}
``````
the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Contact:
hey, don't you think your input and output buffers are smaller than needed?

Code: Select all

``char input[10][10] , click[10][10] , output[10][10] ;``
input is supposed to be <=10 lines and <=10 chars at each line. so your buffer should be 1 char bigger than now...(to hold the terminating '\0')...

Code: Select all

``char input[10][11] , click[10][11] , output[10][11] ;``
that's enough...
Greetings
Istiaque Ahmed [the LA-Z-BOy]
Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm
What a stupid mistake ...

I thought the maximum grid is 8 * 8 ... I didn't read it correctly...

thank you very much the LA-Z-BOy. I finally got AC ...
mafattah
New poster
Posts: 23
Joined: Fri Apr 26, 2002 1:00 am
Location: Cairo, Egypt

10279 Runtime Error! Help!

My program compiles and runs correctly on my test cases, but produces run-time error on the judge. I do not see why. Can anybody help?
[cpp]
#include <iostream.h>

void main() {
int n;
int i, j;
char minearray[12][12];
char inarray[12][12];
int calcarray[12][12];

for (i = 0; i <= 11; i++)
for (j = 0; j <= 11; j++) {
minearray[j] = '.';
inarray[j] = '.';
calcarray[j] = 0;
}
cin >> n;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) {
cin >> minearray[j];
}
char temp;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) {
cin >> temp;
inarray[j] = temp;
if (temp == 'x') {
if (minearray[j] == '*') {
for (int k = 1; k <= n; k++)
for (int l = 1; l <= n; l++)
if (minearray[k][l] == '*') calcarray[k][l] = -1;
}
else {
if (minearray[i-1][j-1] == '*') calcarray[j]++;
if (minearray[i-1][j] == '*') calcarray[j]++;
if (minearray[i-1][j+1] == '*') calcarray[j]++;
if (minearray[j-1] == '*') calcarray[i][j]++;
if (minearray[i][j+1] == '*') calcarray[i][j]++;
if (minearray[i+1][j-1] == '*') calcarray[i][j]++;
if (minearray[i+1][j] == '*') calcarray[i][j]++;
if (minearray[i+1][j+1] == '*') calcarray[i][j]++;
}
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (calcarray[i][j] == -1) cout << '*';
else if (inarray[i][j] == '.') cout << '.';
else cout << calcarray[i][j];
}
cout << endl;
}

}
[/cpp]
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany
The problem is in multiple input format (blue checkmark).
Unfortunately the link given in the head of each volume isn't working any more, so here in short how to read/process the input:
Input:
number of test cases
<blank line>
test case 1 in the format like described in the problem description
<blank line>
test case 2
...
<blank line>
last test case

that means the test cases are separated by blank lines

Output:
print the output for each test case and separate outputs with blank lines.
WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

10279 - Mine Sweeper

Hi,

I don't quite understand the input/output format specification of this
problem.

This problem has no blue check mark, but the description
clearly indicates multiple input. That's true?

As to the output the description says:
Print a blank line between each consecutive 2 consecutive data sets.
Does this mean an additional empty line or does it mean to print
two data sets without any separation and only then output a blank
line? (Btw "consecutive 2 consecutive" is probably a typo?!?)

Well, I submitted both versions, but earned a WA. So there's another
problem. I just want to make sure it's not I/O related.

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

look at this

Hi WR,

here is how the input and output data is set.

Input:

3

8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...

8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...

8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...

Output:

001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...

001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...

001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...

Hope it helps.
WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am
Thanks Sohel,

I thought as much, but wasn't too sure.

My first version was correct as far as the I/O is concerned.

So now I have to look for the serious errors.

Thanks again!
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Contact:

10279

What's the wrong with my code.

Code: Select all

``````Removed after got AC
``````
Last edited by ibrahim on Thu Feb 24, 2005 10:26 pm, edited 1 time in total.
Destination Goa
Experienced poster
Posts: 123
Joined: Thu Feb 10, 2005 4:46 am
I think "<= siz" should be "< siz" everywhere in your code. In 'C' it is convenient to think of array segments in form [a;b), and you do when you read a[j] (i<siz, j<siz), but not in further comparisons.
To be the best you must become the best!
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm