10189 - Minesweeper

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
liusu
New poster
Posts: 22
Joined: Thu Aug 01, 2002 10:26 am

10189

Post by liusu »

why i got WA again and again? are there special inputs? thanks :cry:
Ghost77 dimen
Learning poster
Posts: 67
Joined: Sun Sep 22, 2002 5:40 am
Location: Taiwan

Post by Ghost77 dimen »

I am afraid not.

Maybe something wrong in your code,because I got A.C. at once.
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

to liusu:

if you haven't it AC yet,
maybe you got the same problem with me few while ago

try to use bigger array
vancelee
New poster
Posts: 1
Joined: Fri Jan 17, 2003 9:47 pm

10189 Easy but dunno why wrong answer....sigh.....

Post by vancelee »

:( this is an easy one........ but I still always get wrong answer when submitting to the online judge, I have tested the program with some cases and getting all-correct result.

May anyone please help me to see what's go wrong....?? thanks!!

[c]
/* @JUDGE_ID: 27296JC 10189 C "aaa" */
/* CSC1140@ 02759173 jl3Rjjtv 10189*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char *argv[])
{
/* height and width store the input height and width of the board */
int i, j, height, width, cno;
/* the board stores the minesweeper board */
char board[200][200];
char temp[200][200];

for(cno = 0; ; cno++)
{
/* get the height and width of the first board */
scanf("%d %d", &height, &width);
if(height == 0 && width == 0)
break;

if(cno > 0)
printf("\n");

/* get the input board */
for (i=0; i< height; i++)
scanf("%s", board);

for (i=0; i<200; i++){
for (j=0;j<200; j++){
temp[j]=48;
}
}

for (i=0;i<width;i++){
for (j=0;j<height;j++){
if (board[j]=='*'){
if (i>0 && j>0 && board[i-1][j-1]!='*'){ temp[i-1][j-1]+=1;}
if (j>0 && board[j-1]!='*'){ temp[j-1]+=1;}
if (i<200-1 && j>0 && board[i+1][j-1]!='*'){ temp[i+1][j-1]+=1;}
if (i>0 && board[i-1][j]!='*'){ temp[i-1][j]+=1;}
if (i<200-1 && board[i+1][j]!='*') {temp[i+1][j]+=1;}
if (i>0 && j<200-1 && board[i-1][j+1]!='*'){ temp[i-1][j+1]+=1;}
if (j<200-1 && board[j+1]!='*') {temp[j+1]+=1;}
if (j<200-1 && board[i+1][j+1]!='*') {temp[i+1][j+1]+=1;}
temp[j]='*';
}
}
}




printf("Field #%d:\n", cno + 1);
for (i=0; i< height; i++)
{
for (j=0; j< width; j++)
printf("%c", temp[j]);
printf("\n");
}
}

return 0;
}
[/c]
AllanLin
New poster
Posts: 8
Joined: Thu Jun 26, 2003 3:38 am

10196 - Check The Check

Post by AllanLin »

Dear EVERYONE!

I'm am not sure how to send my programs into the ACM grader...

Here is my program from MINESWEEPER , ID # 10189
Please Help me Find out what is Wrong!
its keeps saying Compiner Error :o

[c]
#include<stdio.h>

int m,n;
char field[100][100]={0};
int map [100][100]={0};

main()
{
int i,j;
char ch;

scanf("%d%d",&m,&n);
while(( m != 0) && ( n!=0 ))
{
//RESET//
for(i=0;i<100;i++)
for(j=0;j<100;j++)
{field[j]=0;
map[j]=0;}

//INPUT//
for(i=1;i<=m;i++)
{ scanf("%c",&ch);
for(j=1;j<=n;j++)
scanf("%c",&field[j]);}

//WORK//
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(field[j] == '*')
{ map[i+1][j+0] ++;
map[i+1][j+1] ++;
map[i+1][j-1] ++;
map[i+0][j+1] ++;
map[i+0][j-1] ++;
map[i-1][j+0] ++;
map[i-1][j+1] ++;
map[i-1][j-1] ++;}

//OUTPUT//
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
if(field[j] == '*') printf("*");
else printf("%d",map[j]);
printf("\n");}

scanf("%d%d",&m,&n);
}
}[/c]








:evil: errrrrrrrr why won't it work!
Last edited by AllanLin on Sun Jun 29, 2003 3:55 am, edited 1 time in total.
Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

Post by Moni »

Welcome! Allan!

I have compiled your code and got only one warning.........

your main function should return a value........


One very important thing.............

Try to post your threads in the related topic..........you may use the volume or language C section for this.........


Carry on :)
ImageWe are all in a circular way, no advances, only moving and moving!
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

Did you submit this code as C programming language? You cannot use // comments in ANSI C, only in C++.
AllanLin
New poster
Posts: 8
Joined: Thu Jun 26, 2003 3:38 am

Thank You Everyone

Post by AllanLin »

I am very lucky to decided to start this ACM training. I have complety amazed with everyone!

Everyone Cares.. and helps those in need.

Thank You! You Guys the best


Yours
Allan Lin
:D
lendlice
New poster
Posts: 22
Joined: Thu Nov 21, 2002 10:50 am

10189 W.A

Post by lendlice »

[cpp]//10189
#include<stdio.h>
main()
{
char in[100][100],out[100][100];
int n,m,i=0,j=0,now=1;
while(scanf("%d%d%*c",&n,&m)==2)
{
if(n==0&&m==0)
break;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%c",&in[j]);
out[j]='0';
}
scanf("%*c");
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(in[j]=='*')
{
out[j]=in[j];
if(i>0&&in[i-1][j]!='*')
out[i-1][j]++;
if(i+1<=n&&in[i+1][j]!='*')
out[i+1][j]++;
if(j+1<=m&&in[j+1]!='*')
out[j+1]++;
if(j>0&&in[j-1]!='*')
out[j-1]++;
if(i>0&&j>0&&in[i-1][j-1]!='*')
out[i-1][j-1]++;
if(i+1<n&&j>0&&in[i+1][j-1]!='*')
out[i+1][j-1]++;
if(i>0&&j<m&&in[i-1][j+1]!='*')
out[i-1][j+1]++;
if(i<n&&j<m&&in[i+1][j+1]!='*')
out[i+1][j+1]++;
}
}
printf("Field #%d:\n",now);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%c",out[j]);
printf("\n");
}
printf("\n");
now++;
}
}[/cpp]
Anyone can help.
I got W.A.
Thanks
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

Increase your array (out) size to 101.

On a 100x100 board, you sometimes attempt to increase out[x][100], which in memory is the same as out[x+1][0] and is thus incrementing something you don't want to.

Also, you can make the array size 102 and start everything at 1, so you don't have to worry about indexes going below 0 as well, and eliminate the bounds checking altogether.

Alternatively, you can just fix your bounds checking, but the above recommendation is probably quicker.
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

A cleaner way to write this instead of all those statements are:

Code: Select all

int dx[] = { 1, 1, 1, 0, 0, -1, -1, -1 };
int dy[] = { 1, -1, 0, 1, -1, 1, 0, -1 };
for ( i = 0; i < 8; i++ )
   /*  Check stuff with x + dx[i] and y + dy[i] */
Makes it easier to read/write and less error prone..
toren
New poster
Posts: 5
Joined: Thu Aug 21, 2003 3:39 pm
Location: Bergen, Norway

10189 - Minesweeper: AC but still...

Post by toren »

Look at the response i got after submitting the solution:

[BEGIN]
Your C++ program has solved Ok the problem 10189 (Minesweeper)
in 0.018 seconds with low memory spent.
Congratulations!

Warning: Your program would get a Presentation Error in a true contest.
The 24-hours judge interpretes it as an "Accepted" problem.
[END]

What does this really mean? I should also mention that i got
WA at http://www.programming-challenges.com. Weird.

--
Tore Nedretvedt
toren
New poster
Posts: 5
Joined: Thu Aug 21, 2003 3:39 pm
Location: Bergen, Norway

Post by toren »

Fixed the problem. I just had to remove the newline after the last field.

--
Tore Nedretvedt
Julien Cornebise
Experienced poster
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France
Contact:

Post by Julien Cornebise »

Hi Tore
PE (or Presentation Error) happens when you've got presentation problems, such as leading or trailing white spaces or new lines, or sometimes trickier errors (but rarely, designing a judge able to deal with complicated errors of that kind is tricky). At the real time contest, you'd have WA.
Programming challenges isn't as nice as uva, talking about PE or even in general : look at its board : very many people are complaining about uva's AC problems, and WA on p-c. I agree that p-c might be testing some trickier input than uva, but it doesn't explain why SO MANY problems arise. Problems in latency time in answers, or running time much slower than UVA, etc, are also reported.
I've been really disapointed by programming-challenges. In my opinion, The book is as good as the site is bad : while the book is good, with a few bad points, the site is bad, with a (very) few good points.
So let's take best of both worlds : Programming challenges Book, and UVA website :)
To conclude on P-c, I would say that it is a fairly good introduction to Skiena's reference : Algorithm design manual. I learned a lot by beginning a subject with p-c and goind deeper with adm (for Dynamic Programming, specially).
toren
New poster
Posts: 5
Joined: Thu Aug 21, 2003 3:39 pm
Location: Bergen, Norway

Post by toren »

OK, thanks for the tip. Just another thing about PE. I've experienced
PE for one problem when I wrote a new line after the last output, and then got it fixed when I removed it. But, to the contrary, I've also experienced PE for another problem when I didn't write a newline after the last output, and then got it fixed by outputing a newline at the end. Go figure.

--
Tore Nedretvedt
Post Reply

Return to “Volume 101 (10100-10199)”