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
Qodeus
New poster
Posts: 6
Joined: Mon Mar 06, 2006 10:32 pm

Post by Qodeus » Thu Mar 09, 2006 6:48 pm

Oh, I can't beleve that i didn't see that. :oops: Thanks a lot man! :D

xivphoenix
New poster
Posts: 3
Joined: Wed May 24, 2006 3:29 pm
Location: Thailand

10189 mines WA!

Post by xivphoenix » Thu May 25, 2006 3:01 pm

I've no idea what's wrong whith my code.somebody plz help. THX.

Here's my code.

Code: Select all

#include <stdio.h>

int main(void)
{
	int arr[150][150];
	int i,j,mrow,mcol,cnt=0;
	char c[200];

	while(scanf("%d%d ",&mrow,&mcol)!=EOF) {
		if(mrow==0 && mcol==0) break;
		printf("Field #%d:\n",++cnt);

		for(i=0 ; i<mrow ; i++) {
			scanf("%s",c);
			for(j=0 ; j<mcol ; j++) {
				if(c[j]=='*') 	arr[i][j] = -100;
				else 							arr[i][j] =  0;
			}
		}

		for(i=0 ; i<mrow ; i++) {
			for(j=0 ; j<mcol ; j++) {
				if (arr[i][j] < 0) {
					arr[i-1][j-1] ++;  arr[i-1][j] ++; 	arr[i-1][j+1] ++;
					arr[i][j-1] ++;  	 arr[i][j] ++; 	  arr[i][j+1] ++;
					arr[i+1][j-1] ++;  arr[i+1][j] ++; 	arr[i+1][j+1] ++;
				}
			}
		}

		for(i=0 ; i<mrow ; i++) {
			for(j=0 ; j<mcol ; j++) {
				if (arr[i][j] > -1) printf("%d",arr[i][j]);
				else							  printf("*");
			}
			printf("\n");
		}

		printf("\n");

	}

	return 0;
}

ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi » Mon May 29, 2006 8:21 pm

hi there!
i didnt run ur code but probably u r getting out of array boundary by these lines.........

for(i=0 ; i<mrow ; i++) {
for(j=0 ; j<mcol ; j++) {
if (arr[j] < 0) {
arr[i-1][j-1] ++; arr[i-1][j] ++; arr[i-1][j+1] ++;
arr[j-1] ++; arr[j] ++; arr[j+1] ++;
arr[i+1][j-1] ++; arr[i+1][j] ++; arr[i+1][j+1] ++;
}
}
}
what abt arr[0-1][0-1]???

northboy
New poster
Posts: 2
Joined: Sat Jun 17, 2006 8:02 pm

What is Presentation error I don't understand it

Post by northboy » Sat Jun 17, 2006 8:11 pm

Dear North:

Your C++ program has solved Ok the problem 10189 (Minesweeper)
in 0.008 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.

--

PS: Check the board at http://acm.uva.es/board/

The Online Judge (Linux acm.uva.es 2.4.18-27.7.x i686)
Judge software version 2.8 [http://acm.uva.es/problemset/]
Sat Jun 17 17:43:03 UTC 2006


I can't understand about this mail please tell me what is presentation error thanks for answer

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes » Sat Jun 17, 2006 8:44 pm

Presentation Error means that your program worked well for all the testcases but the position of your output might not be put in order...

For example,the problem encourages you not to put a blank line after the last testcase,but your program did it...

Hope it helps... :wink:

northboy
New poster
Posts: 2
Joined: Sat Jun 17, 2006 8:02 pm

Post by northboy » Sun Jun 18, 2006 5:43 am

Oh I see Thank you very much for answer :D

SHAHADAT
New poster
Posts: 23
Joined: Thu Jun 22, 2006 8:55 am
Location: sust,bangladesh

Post by SHAHADAT » Sun Jun 25, 2006 9:53 am

Please delete your code....
And it,s not good idea to upload a code and say whats wrong?????
Try to disscuss about algorithm....

AikoSenoo
New poster
Posts: 3
Joined: Tue Jul 18, 2006 5:28 pm

10189WA

Post by AikoSenoo » Tue Jul 18, 2006 5:34 pm

I have tried many means to test,but still got WA.

Would you please help me to find where my code's problem is?

Thanks a lot!

There is my code:

Code: Select all

#include<stdio.h>
#include<stdlib.h>
char a[102][102];
int n,m;
int check(int j,int i,int m){
        int count=0;
        if(a[j][i]=='*')
            return 9;
        else {
            if(j!=0){     
                  if(a[j-1][i-1]=='*' && i!=0)
                      count++;            
                  if(a[j-1][i]=='*')
                        count++;
                  if(a[j-1][i+1]=='*')
                        count++;
                
            }
            if(a[j][i-1]=='*' && i!=0)
                count++;
            if(a[j][i+1]=='*')
                count++;
            if(j!=m){
              if(a[j+1][i-1]=='*' && i!=0)
                  count++;
              if(a[j+1][i]=='*')
                  count++;
              if(a[j+1][i+1]=='*')
                  count++;
            }
            return count+'0';
        }
                                                                                
}
                                                                                
int main(void){
    int cnt=0;
    int i,j;
                                                                                
    while(1){
        scanf("%d %d",&n,&m);
        if(n==0 && m==0)
          break;
        cnt++;
        for(j=0;j<n;j++){
            for(i=0;i<m;i++){
                a[j][i]='.';
            }
        }
        for(j=0;j<n;j++){
            for(i=0;i<m;i++){
                scanf(" %c",&a[j][i]);
            }
        }
        for(j=0;j<n;j++){
            for(i=0;i<m;i++){
                if(check(j,i,m)!=9)
                    a[j][i]=check(j,i,m);
            }
        }
        if(cnt>1)printf("\n");
        printf("Field #%d:\n",cnt);
        for(j=0;j<n;j++){
            for(i=0;i<m;i++)
                printf("%c",a[j][i]);
            printf("\n");
        }
        
    }
    return 0;
}

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko » Tue Jul 18, 2006 6:52 pm

Clear the whole array, not just mxn (if board is smaller than the previous one, you might get WA) Or clear it after each case (not at the beginning).

code_man
New poster
Posts: 4
Joined: Tue Jan 16, 2007 6:07 pm

10189

Post by code_man » Wed Feb 14, 2007 7:51 pm

what is wrong with this code? I have WA.. I don't undersand why...?

Code: Select all

#include<iostream>
using namespace std;

char check(char t)
{
 int i=0;
 if(t!=42) i=1; 
  return i;   
}

main()
{
int a, b, it=1;

 while(cin>>a>>b)
 {
  if((a==0) && (b==0)) break;
  
  char **t;
  t= new char*[a+5];
  for(int i=0; i<a+5; i++)
   t[i] = new char[b+5];
   
  for(int i=0; i<a+5; i++)
   {
     for(int j=0; j<b+5; j++)
      t[i][j]=48;
   } 
   
  char z; 
  for(int i=1; i<a+1; i++)
   {
     for(int j=1; j<b+1; j++)
      {
        cin>>z;
        if(z==42)
         {
          t[i][j]=42;          
          t[i-1][j-1]+=check(t[i-1][j-1]);
          t[i-1][j]+=check(t[i-1][j]);
          t[i-1][j+1]+=check(t[i-1][j+1]);
          t[i][j-1]+=check(t[i][j-1]);
          t[i][j+1]+=check(t[i][j+1]);
          t[i+1][j-1]+=check(t[i+1][j-1]);
          t[i+1][j]+=check(t[i+1][j]);
          t[i+1][j+1]+=check(t[i+1][j+1]);       
         }   
      } 
    }
  
  cout<<"\nField #"<<it++<<"\n";
  for(int i=1; i<a+1; i++)
   {    
    for(int j=1; j<b+1; j++)
     {
      cout<<t[i][j];
     }
    cout<<"\n";
    }
  
   
  for(int i=a; i<a+5; i++)
    delete [] t[i];
   delete [] t; 
 }      
}
Last edited by code_man on Fri Feb 23, 2007 10:16 pm, edited 1 time in total.

big_mac
New poster
Posts: 1
Joined: Thu Feb 15, 2007 1:22 am

Post by big_mac » Thu Feb 15, 2007 1:24 am

The first things I can see is that you are printing a '\n' before the first 'Field', and no ':' after the field number.

m2lajoo
New poster
Posts: 11
Joined: Thu Jan 11, 2007 9:21 am
Location: iran

10189:how to present

Post by m2lajoo » Thu Feb 15, 2007 6:09 pm

help me! why my program say presentation error :cry:

Code: Select all

var
m,n:byte;
test:integer;
house:array[1..100,1..100]of char;
st:string;
khane:array[1..100,1..100]of (mine,clear);
h:array[1..100,1..100]of byte;
i,j:integer;
function shownumber(num1,num2:integer):integer;
var
x,y,tedad:integer;
begin
tedad:=0;
for x:=num1-1 to num1+1 do
for y:=num2-1 to num2+1 do
if (khane[x,y]=mine)and(x<=m)and(x>=1)and(y<=n)and(y>=1) then
tedad:=tedad+1;
shownumber:=tedad;
end;
begin
readln(m,n);
test:=1;
while (m<>0)or(n<>0) do
begin
for i:=1 to m do
for j:=1 to n do
begin
khane[i,j]:=clear;
house[i,j]:='.';
h[i,j]:=0;
end;
for i:=1 to m do
begin
readln(st);
for j:=1 to length(st) do
house[i,j]:=st[j];
end;
writeln('Field #',test,':');
for i:=1 to m do
for j:=1 to n do
if house[i,j]='*' then
khane[i,j]:=mine
else
khane[i,j]:=clear;
for i:=1 to m do
for j:=1 to n do
if khane[i,j]<>mine then
h[i,j]:=shownumber(i,j);
for i:=1 to m do
begin
for j:=1 to n do
if khane[i,j]<>mine then
write(h[i,j])
else
write('*');
writeln;
end;
writeln
test:=test+1;
readln(m,n);
end;
end.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Thu Feb 15, 2007 6:41 pm

Just try to search first.. and..
Do not make a new thread if there is one already..

http://online-judge.uva.es/board/viewtopic.php?t=8869

Don't forget to remove your code after AC.. :)

code_man
New poster
Posts: 4
Joined: Tue Jan 16, 2007 6:07 pm

Post by code_man » Fri Feb 23, 2007 9:58 pm

thx big_mac for you help..:) Now I know whats was incorrect..

User avatar
KaDeG
New poster
Posts: 13
Joined: Sun Mar 04, 2007 8:40 pm

10189 WA

Post by KaDeG » Sun Mar 04, 2007 9:45 pm

I have made the minsweeper program but i got WA,
I checked some testcases I found in the forums and everything works fine,
any ideas where the probelm is?

Code: Select all

Code, deleted, thanks 
I'm a bit complicate with all thes \n that can give a WA, any suggestion would be very hepful, thanks.
Last edited by KaDeG on Mon Mar 05, 2007 1:34 pm, edited 1 time in total.
/*No Comment*/

Post Reply

Return to “Volume 101 (10100-10199)”