10279 - Mine Sweeper

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

Moderator: Board moderators

User avatar
ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Post by ibrahim » Thu Feb 24, 2005 10:24 pm

Finaly i got AC :D (After change the full code) :( .

Salman
New poster
Posts: 25
Joined: Thu Jun 26, 2003 9:45 am

10279

Post by Salman » Wed Aug 24, 2005 9:58 am

Getting WA ?Some one help?

Code: Select all


/*
Name: Mine Sweeper   
Number: 10279
Type :  simulation
Process : ON
Author :Salman Zaman
Email : zamansalman@gmail.com
Date : 15/08/05 20:10



*/



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



//#include<conio.h>



int main(){

       int t,n,i,j,k;
       int mines[200][200];
       int touch[200][200];
       int output[200][200];
       char input[100];

  //     freopen("10279.txt","r",stdin);
//       printf("%d",'.');
       gets(input);
       sscanf(input,"%d",&t);
       for(k=0;k<t;k++){
           gets(input); 
           gets(input);
           sscanf(input,"%d",&n);

            for(i=0;i<=n;i++){
               for(j=0;j<=n;j++){
                   mines[i][j]=0;
                   output[i][j]=0;
                   touch[i][j]=0;
                   
               }    
             
            }    

 
           for(i=1;i<=n;i++){
               gets(input);
                for(j=0;j<n;j++){
                   if(input[j]=='.'){
                       mines[i][j+1]=0;     
                   }
                   else if(input[j]=='*'){
                       mines[i][j+1]=1;
                   }         
               }    
           }    
           for(i=1;i<=n;i++){
                gets(input);
                for(j=0;j<n;j++){
                  if(input[j]=='x'){
                      touch[i][j+1]=1;
                  }    
                  else if(input[j]=='.'){
                      touch[i][j+1]=0;  
                  }    
               }       
                 
           }    
           for(i=1;i<=n;i++){
               
               for(j=1;j<=n;j++){
     //             printf("%d ",touch[i][j]);
                     if(touch[i][j]){ 
                            if(i-1>=1 && j-1>=1){
                                output[i][j]+=mines[i-1][j-1];      
                            }    
                            if(i-1>=1) {
                                output[i][j]+=mines[i-1][j];      
                                
                            }    
                            if(i-1>=1 && j+1<=n){
                                output[i][j]+=mines[i-1][j+1];      
                                
                            }    
                            if(j-1>=1){
                                output[i][j]+=mines[i][j-1];      
                                
                            }        
                            if(j+1<=n){
                                output[i][j]+=mines[i][j+1];      
                               
                            }    
                            if(i+1<=n && j-1>=1){
                                output[i][j]+=mines[i+1][j-1];      
                                
                            }    
                            if(i+1<=n){
                                output[i][j]+=mines[i+1][j];      
                                
                            }    
                            if(i+1<=n && j+1<=n){
                                output[i][j]+=mines[i+1][j+1];      
                                
                            }    
//                          output[i][j]='1';
                    }     
                    else {
                        output[i][j]=46;    
                    }    
           
               }    
       //        printf("\n");
          }    

           for(i=1;i<=n;i++){
                for(j=1;j<=n;j++){
                 if(output[i][j]==46){
                     printf("%c",'.');
                 }
                 else{     
                  printf("%d",output[i][j]);
                 }    


             }       
             printf("\n");
         }    


          printf("\n\n"); 
           
       }    

     
//   getch();
   return 0;
}

User avatar
mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Post by mohiul alam prince » Wed Aug 24, 2005 11:56 am

Hi salman

Try this input

Input

Code: Select all

1

8 
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxxxxxxx
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...
Output

Code: Select all

001**22*
0013..*.
0001*...
00011...
00001...
00123*..
001**.*.
00123*..
for this input your output is

Output

Code: Select all

00111221
0013....
0001....
00011...
00001...
00123...
001.....
00123...
Thanks
MAP

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

10279 Why WA ????

Post by jan_holmes » Tue Oct 04, 2005 3:41 pm

Anyone could help me why is my source is still wrong ???

#include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int main () {
int n,m;
char sign[150][150];
char sign2[150][150];
int number[150][150];
cin >> n;
for (int i=0;i<n;i++) {
memset(number,0,sizeof(number));
cin >> m;
for (int j=0;j<m;j++) {
for (int k=0;k<m;k++) {
cin >> sign[j][k];
if (sign[j][k] == '*') {
if (k-1 >= 0 ) number[j][k-1]++;
if (k+1 < m) number[j][k+1]++;
if (j-1 >= 0) number[j-1][k]++;
if (j+1 < m) number[j+1][k]++;
if (j-1 >=0 && k-1 >=0) number[j-1][k-1]++;
if (j-1 >=0 && k+1 < m) number[j-1][k+1]++;
if (j+1 < m && k-1 >=0) number[j+1][k-1]++;
if (j+1 < m && k+1 < m) number[j+1][k+1]++;
}
}
}
for (int j=0;j<m;j++) {
for (int k=0;k<m;k++) {
cin >> sign2[j][k];
}
}
for (int j=0;j<m;j++) {
for (int k=0;k<m;k++) {
if (sign2[j][k] == 'x') {
if (sign[j][k] == '.') {
cout << number[j][k];
}
else if (sign[j][k] == '*') {
cout << sign[j][k];
}
}
else {
if (sign[j][k] == '*') cout << sign[j][k];
else cout << sign2[j][k];
}
}
cout << "\n";
}
if (i != n-1) cout << "\n";
}
return 0;
}

Niaz
Learning poster
Posts: 77
Joined: Fri Dec 17, 2004 11:06 am
Location: East West University, Dhaka, Bangladesh
Contact:

Post by Niaz » Sun Oct 09, 2005 3:20 pm

It looks an easy one but its pulling my brain out by showing WA again and again. Plz check my code and do some comment.

Another thing, will there be any blank line after the last case ?

Code

Code: Select all

#include<stdio.h>
char grid[20][20],extra[20][20];
void putmine(int n)
{
    int i,j;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            if(grid[i][j]=='*')
                extra[i][j]='*';    
}
int count(int i,int j, int n)
{
    int s=0;
    if(i<n-1)
        if(grid[i+1][j]=='*')
            s++;    
    
    if(i<n-1 && j<n-1)
        if(grid[i+1][j+1]=='*')
            s++;
    
    if(j<n-1)
        if(grid[i][j+1]=='*')
            s++;
    
    if(i>0)
    {
        if(grid[i-1][j]=='*')
            s++;           
        if(grid[i-1][j+1]=='*')
            s++;
    }
    
    if(j>0)
    {
        if(grid[i][j-1]=='*')
            s++;
        if(grid[i+1][j-1]=='*')
            s++;
    }
    if(i>0 && j>0)
    {
        if(grid[i-1][j-1]=='*')
            s++;
    }
    return s;
}    
int main()
{
    int i,j,N,n,s,chk;
    scanf("%d",&N);
    while(N--)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
            scanf("%s",grid[i]);
        
        for(i=0;i<n;i++)
            scanf("%s",extra[i]);
        
        chk=1;    
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if(extra[i][j]=='x')
                {
                    if(grid[i][j]=='*')
                        chk=0;
                    s=count(i,j,n);
                    extra[i][j]=s+48;
                }                   
            }    
        }
        if(chk==0)
            putmine(n);
        for(i=0;i<n;i++)
            printf("%s\n",extra[i]);
        
        //if(N!=0)
            printf("\n");
    }    
}
Thanks in advance.
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR » Thu Dec 15, 2005 3:51 pm

Try this one:

Code: Select all

1
.
x

CrazyTerabyte
New poster
Posts: 25
Joined: Fri Jul 16, 2004 3:19 am
Location: Brazil
Contact:

10279

Post by CrazyTerabyte » Wed Apr 19, 2006 7:19 pm

It reads "The first line of input contains how many game you have to solved followed by blank line.", it should read: "The first line of input contains how many games you have to solve followed by blank line."

Ok, this is a really small change, but I felt I should report it.

I'm not sure where I should post this, if at this forum or at "Bugs and suggestions".

Thanks.

razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue » Thu Nov 30, 2006 3:28 am

Sorry, I still don't get the point of the problem.
Can someone tell me what is the output for this:

Code: Select all

1

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

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Thu Nov 30, 2006 8:23 am

My accepted code returns

Output:

Code: Select all

001**..*
0013..*.
0001*...
00011...
00001...
00123*..
001**.*.
00123*..
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue » Sat Dec 02, 2006 3:07 am

Thx, now I understand the problem and I've solved it.

albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar » Wed Jan 03, 2007 10:06 am

got AC..
at last i know where i do mistake..

:) :wink:

vijay03
New poster
Posts: 33
Joined: Wed Sep 13, 2006 6:46 pm
Contact:

Wa :(

Post by vijay03 » Tue Jan 16, 2007 3:52 pm

I`ve taken care of it being a multiple input problem and i`ve printed the blank lines between consecutive cases. My program gives the correct output for all the i/o on this forum. Why WA?

Code: Select all


#include<stdio.h>

int main()
{
	char area [102][102];
	char output [102][102];
	char used[102][102];
	int m,n,i,j,k,flag=0;
	char c;
	scanf("%d\n",&n);
	for(k=0;k<n;k++)
	{
		scanf("%d",&m);
		
		flag=0;

		for(i=0;i<m;i++)
			for(j=0;j<m;j++)
				output[i][j]='0';
		
		for(i=0;i<m;i++)
			for(j=0;j<m;j++)
			{
				scanf("%c",&c);
				if(c=='\n')
				{
					j--;
				}
				else
				{
					area[i][j]=c;
					if(area[i][j]=='*')
						{
							output[i][j]='*';
							if(i!=0)
								{
									if(output[i-1][j]!='*')
									output[i-1][j]++;
									if(j!=m-1)
										if(output[i-1][j+1]!='*')
											output[i-1][j+1]++;
									if(j!=0)
										if(output[i-1][j-1]!='*')
											output[i-1][j-1]++;
								}
							if(j!=0)
								if(output[i][j-1]!='*')
									output[i][j-1]++;
							if(j!=m-1)
								if(output[i][j+1]!='*')
								output[i][j+1]++;

							if(i!=m-1)
								{
									if(output[i+1][j]!='*')
									output[i+1][j]++;
									if(j!=0)
										 if(output[i+1][j-1]!='*')
										output[i+1][j-1]++;
								}
							
							if(!i&&!j)
								if(output[i-1][j-1]!='*')
								output[i-1][j-1]++;
							if((i!=m-1)&&(j!=m-1))
								if(output[i+1][j+1]!='*')
								output[i+1][j+1]++;
					}
				}
			}

			for(i=0;i<m;i++)
				for(j=0;j<m;j++)
				{
					scanf("%c",&c);
					if(c=='\n')
					{
						j--;
					}
					else
					{
						used[i][j]=c;
						if(!flag)
						{
							if(c=='X')
							if(area[i][j]=='*')
								flag=1;
						}
					}
				}

			if(k)
				printf("\n");			
			

			
			for(i=0;i<m;i++)
			{
				for(j=0;j<m;j++)
				{
					if(flag)
					{
						if(area[i][j]=='*')
							printf("%c",'*');
						else
							if(used[i][j]=='X')
								printf("%c",output[i][j]);
							else
								printf("%c",'.');
					}
					else
					{
						if(used[i][j]=='X')
								printf("%c",output[i][j]);
							else
								printf("%c",'.');
					}

				}
				printf("\n");
			}

			
	}
	return 0;
}

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

why 10279 mine sweeper WA

Post by bishop » Sat Jul 28, 2007 12:34 pm

i test all input output
but still WA

Code: Select all

for 
1

1
.
x
Thanks rio 


:D
Last edited by bishop on Thu Aug 02, 2007 12:38 pm, edited 1 time in total.

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

can anyone

Post by bishop » Wed Aug 01, 2007 7:42 pm

CAN anyone tell me what is wrong for

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

can anyone

Post by bishop » Wed Aug 01, 2007 7:43 pm

CAN anyone tell me what is wrong for
result shows wrong ans

Post Reply

Return to “Volume 102 (10200-10299)”