10189 - Minesweeper

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

Moderator: Board moderators

10189

Postby liusu » Thu Oct 03, 2002 12:32 pm

why i got WA again and again? are there special inputs? thanks :cry:
liusu
New poster
 
Posts: 22
Joined: Thu Aug 01, 2002 10:26 am

Postby Ghost77 dimen » Fri Oct 04, 2002 1:21 pm

I am afraid not.

Maybe something wrong in your code,because I got A.C. at once.
User avatar
Ghost77 dimen
Learning poster
 
Posts: 67
Joined: Sun Sep 22, 2002 5:40 am
Location: Taiwan

Postby deddy one » Mon Dec 23, 2002 7:40 pm

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
deddy one
Experienced poster
 
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

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

Postby vancelee » Fri Jan 17, 2003 9:51 pm

:( 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[i]);

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

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




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

return 0;
}
[/c]
vancelee
New poster
 
Posts: 1
Joined: Fri Jan 17, 2003 9:47 pm

10189 W.A

Postby lendlice » Wed Jul 23, 2003 5:27 am

[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[i][j]);
out[i][j]='0';
}
scanf("%*c");
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(in[i][j]=='*')
{
out[i][j]=in[i][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[i][j+1]!='*')
out[i][j+1]++;
if(j>0&&in[i][j-1]!='*')
out[i][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[i][j]);
printf("\n");
}
printf("\n");
now++;
}
}[/cpp]
Anyone can help.
I got W.A.
Thanks
lendlice
New poster
 
Posts: 22
Joined: Thu Nov 21, 2002 10:50 am

Postby UFP2161 » Thu Jul 31, 2003 6:12 am

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.
User avatar
UFP2161
A great helper
 
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm

Postby Larry » Thu Jul 31, 2003 7:26 pm

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..
Larry
Guru
 
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City

10189 - Minesweeper: AC but still...

Postby toren » Thu Aug 21, 2003 3:45 pm

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

Postby toren » Thu Aug 21, 2003 3:56 pm

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

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

Postby Julien Cornebise » Thu Aug 21, 2003 4:42 pm

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).
Julien Cornebise
Experienced poster
 
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France

Postby toren » Sun Aug 24, 2003 4:25 pm

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
toren
New poster
 
Posts: 5
Joined: Thu Aug 21, 2003 3:39 pm
Location: Bergen, Norway

Postby Julien Cornebise » Sun Aug 24, 2003 6:26 pm

Well, don't care too much about PE, if adding or taking off a newline doesn't solve it. It might be that the judge output has itself a PE compared to the theorical output (it already happened) :)
Julien Cornebise
Experienced poster
 
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France

10189 Why WA?

Postby zilnus » Thu Sep 04, 2003 9:20 am

[c]
int main()
{
int i,j,k,l,m,a,b;
int win[200][200];
int nextx[8] = {-1,-1,-1,0,0,1,1,1};
int nexty[8] = {-1,0,1,-1,1,-1,0,1};
char string[150];
int kasus = 1;

while ((i != 0)&&(j != 0))
{
scanf("%d %d",&i,&j);

for (a=0;a<105;a++)
for (b=0;b<105;b++)
win[a][b] = 0;

for (k=1;k<=i;k++) {
scanf("%s",string);
for (l=0;l<j;l++) {
if (string[l] == '*') win[k][l+1] = -1;
}
}

for (k=1;k<=i;k++){
for (l=1;l<=j;l++){
for (m=0;m<8;m++) {
if (win[k][l] != -1) {
if (win[k + nextx[m] ][l + nexty[m] ] == -1) win[k][l] = win[k][l] + 1;
}
}
}
}

if ((i==0)&&(j==0)) exit(-1);
printf ("Field #%d:\n",kasus);
kasus++;
for (k=1;k<=i;k++) {
for (l=1;l<=j;l++) {
if (win[k][l] == -1) printf ("*");
else printf ("%d",win[k][l]);
}
printf ("\n");
}
}

return 0;
}[/c]

Anyone please help me ? Why wrong answer ???
zilnus
New poster
 
Posts: 9
Joined: Sat Mar 08, 2003 11:59 am

Postby titid_gede » Thu Sep 04, 2003 2:52 pm

hi zilnus... you're from bandung, rite?

looking at the code.. when i == 0 and j == 0, your code doesnt immediately break, but read input first, perhaps it can cause error..

regards,
titid
Kalo mau kaya, buat apa sekolah?
titid_gede
Experienced poster
 
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Postby Joseph Kurniawan » Fri Sep 05, 2003 9:35 am

You just have to change the part:
[c]
while ((i != 0)&&(j != 0))
{
scanf("%d %d",&i,&j);
[/c]

with

[c]
while(scanf("%i %i",&i,&j)){
if(!i&&!j) break;
[/c]

That'll solve it (but very possibly with P.E.)!! :wink: :wink:
There are 3 things one need to be successful : motivation, ability and chance. And if you're a believer, make it four : God's will.
Joseph Kurniawan
Experienced poster
 
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

Next

Return to Volume CI

Who is online

Users browsing this forum: No registered users and 0 guests

cron