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

sajibcse
New poster
Posts: 1
Joined: Fri Aug 03, 2012 4:56 pm
Location: Chittagong University of Engineering and Technology
Contact:

Re: 10279 - Mine Sweeper

Post by sajibcse » Fri Aug 03, 2012 5:19 pm

Check this line : "If a mine has been touched, all positions with a mine should contain an asterisk".
input :
1

3
.*.
..*
..*
xx.
...
...
output :
1*.
..*
..*

mahmudul
New poster
Posts: 1
Joined: Mon Aug 27, 2012 5:50 pm
Location: Dhaka,Bangladesh
Contact:

Re: 10279 - Mine Sweeper

Post by mahmudul » Mon Aug 27, 2012 6:10 pm

WA.please help

Code: Select all

Removed after ACCEPTED 

graph_dp
New poster
Posts: 7
Joined: Fri Sep 14, 2012 8:33 am

i am getting WA at uva=10279(Mine Sweeper)

Post by graph_dp » Thu Jan 17, 2013 7:41 pm

# include <iostream>
# include <cstdio>

using namespace std;

int cx[]={-1,-1,-1,0,0,1,1,1};
int cy[]={-1,0,1,-1,1,-1,0,1};
char g[100][100];int n,m;
int DFS(int x,int y){
int cnt=0;
for(int i=0;i<8;i++){
if(g[x+cx][y+cy]=='*'){
cnt++;
}

}
return cnt;
}

int main (){

int i,j,k=1;
bool flag=false;
while(cin>>n>>m){
if(!n && !m) break;
if(flag)cout<<endl;flag=true;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cin>>g[j];
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(g[j]!='*' && g[j]=='.'){
g[j]=(DFS(i,j)+'0');
}

}

}
cout<<"Field #"<<k++<<":"<<endl;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cout<<g[j];
}
cout<<endl;
}




}
return 0;}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: i am getting WA at uva=10279(Mine Sweeper)

Post by brianfry713 » Thu Jan 17, 2013 8:55 pm

line 12 should be
if(x+cx>=0 && y+cy>=0 && x+cx<n && y+cy<m && g[x+cx][y+cy]=='*'){
Check input and AC output for thousands of problems on uDebug!

dibery
Learning poster
Posts: 76
Joined: Sat Feb 23, 2013 4:16 pm
Location: Taiwan, Taipei
Contact:

Re: 10279 - Mine Sweeper

Post by dibery » Tue Jun 18, 2013 10:22 am

I kept getting WA on this problem.
Can someone help me?
Thanks in advance. :)

Code: Select all

Thanks, Brianfry.
I got AC.
Last edited by dibery on Sun Jul 21, 2013 6:45 pm, edited 1 time in total.
Life shouldn't be null.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 » Wed Jun 19, 2013 1:39 am

Don't print null chars.
Check input and AC output for thousands of problems on uDebug!

??????
New poster
Posts: 6
Joined: Thu Jun 13, 2013 5:40 am

Re: 10279 - Mine Sweeper

Post by ?????? » Sat Jul 06, 2013 6:47 pm

Why WA?? :( :(

Code: Select all

#include <stdio.h>
#include <string.h>
int main()
{
char s[1000][1000],ss[1000][1000],ch;
long long int n,m,i,j,x,y,i1,j1,t,T,C;
scanf("%lld",&T);printf("\n");
for(t=1;t<=T;)
{
    C=0;
scanf("%lld",&n);m=n;
for(i=0;i<n;i++){for(j=0;j<m;){scanf("%c",&ch);if(ch=='*'||ch=='.') { s[i][j]=ch; if(ch=='.') {s[i][j]='0';} j++; }}}i=0;j=0;
for(i=0;i<n;i++){for(j=0;j<m;){scanf("%c",&ch);if(ch=='x'||ch=='.') { ss[i][j]=ch; if(ch=='.') {ss[i][j]='0';} j++; }}}i=0;j=0;
for(x=0;x<n;x++)
{
for(y=0;y<m;y++)
{
if(s[x][y]=='*')
{
if(x!=0 && y!=0 && x!=n-1&&y!=m-1)
{
if(s[x-1][y-1]!='*') {s[x-1][y-1]=s[x-1][y-1]+1; }
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x-1][y+1]!='*') {s[x-1][y+1]=s[x-1][y+1]+1;}
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1;}
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
if(s[x+1][y-1]!='*') {s[x+1][y-1]=s[x+1][y-1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1;}
if(s[x+1][y+1]!='*') {s[x+1][y+1]=s[x+1][y+1]+1;}
}
else if(x==0 && y!=0 && y!=m-1)
{
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1; }
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
if(s[x+1][y-1]!='*') {s[x+1][y-1]=s[x+1][y-1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1; }
if(s[x+1][y+1]!='*') {s[x+1][y+1]=s[x+1][y+1]+1;}
}
else if(x==n-1 && y!=0 && y!=m-1)
{
if(s[x-1][y-1]!='*') {s[x-1][y-1]=s[x-1][y-1]+1;}
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x-1][y+1]!='*') {s[x-1][y+1]=s[x-1][y+1]+1;}
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1; }
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
}
else if(y==0 && x!=0&& x!=n-1)
{
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x-1][y+1]!='*') {s[x-1][y+1]=s[x-1][y+1]+1;}
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1; }
if(s[x+1][y+1]!='*') {s[x+1][y+1]=s[x+1][y+1]+1;}
}
else if(y==m-1 && x!=n-1&&x!=0)
{
if(s[x-1][y-1]!='*') {s[x-1][y-1]=s[x-1][y-1]+1;}
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1;}
if(s[x+1][y-1]!='*') {s[x+1][y-1]=s[x+1][y-1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1;}
}
else if(x==0&&y==0)
{
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1;}
if(s[x+1][y+1]!='*') {s[x+1][y+1]=s[x+1][y+1]+1;}
}
else if(x==n-1&&y==0)
{
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x-1][y+1]!='*') {s[x-1][y+1]=s[x-1][y+1]+1;}
if(s[x][y+1]!='*') {s[x][y+1]=s[x][y+1]+1;}
}
else if(x==0&&y==m-1)
{
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1; }
if(s[x+1][y-1]!='*') {s[x+1][y-1]=s[x+1][y-1]+1;}
if(s[x+1][y]!='*') {s[x+1][y]=s[x+1][y]+1;}
}
else if(x==n-1&&y==m-1)
{
if(s[x-1][y-1]!='*') {s[x-1][y-1]=s[x-1][y-1]+1;}
if(s[x-1][y]!='*') {s[x-1][y]=s[x-1][y]+1;}
if(s[x][y-1]!='*') {s[x][y-1]=s[x][y-1]+1; }
}
}
}
}

for(i=0;i<n;i++){for(j=0;j<m;j++){ if(ss[i][j]=='x') {ss[i][j]=s[i][j];if(s[i][j]=='*') {C=1;}} else ss[i][j]='.';  }}i=0;j=0;
if(C==1) { for(i=0;i<n;i++){for(j=0;j<m;j++){ if(s[i][j]=='*') {ss[i][j]='*';}   }} }i=0;j=0;
for(i=0;i<n;i++){for(j=0;j<m;j++){  printf("%c",ss[i][j]);  }printf("\n");}i=0;j=0;

if(t!=T)printf("\n");
t++;}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 » Tue Jul 09, 2013 1:07 am

Don't print a blank line at the start of the output.
Check input and AC output for thousands of problems on uDebug!

hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

Re: 10279 - Mine Sweeper

Post by hello » Fri Oct 18, 2013 11:30 pm

What's the problem....?

Code: Select all

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#define zero(arr) memset(arr,0,sizeof(arr));
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,k) for(int i=0;i<n;i=i+k)

#define VI vector<int>
#define VVI vector< VI >
#define VIit VI::iterator

#define pb(a) push_back(a)
#define SI(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SLLD(a) scanf("%lld",&a)
#define SLLU(a) scanf("%llu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

using namespace std;

int dirR8[]= {0,-1,-1,-1,0,1,1,1};
int dirC8[]= {1,1,0,-1,-1,-1,0,1};
int dirR4[]= {0,-1,0,1};
int dirC4[]= {1,0,-1,0};
char grid1[11][11];
char grid2[11][11];
int cnt;

int main()
{
    int cases;
    SI(cases);
    int sp=0;
    while(cases--)
    {
        int flag=0;
        int rc;
        if(sp)cout<<endl;
        sp=1;
        SI(rc);
        getchar();
        rep(i,rc)gets(grid1[i]);
        rep(i,rc)rep(j,rc){
            cin>>grid2[i][j];
            if(grid2[i][j]=='x' && grid1[i][j]=='*'){flag=1;grid2[i][j]='.';}
            }

        rep(i,rc)rep(j,rc)if(grid2[i][j]=='x')
        {
            cnt=0;
            rep(k,8)
            {
                int R=i+dirR8[k];
                int C=j+dirC8[k];
                if(R>=0 && C>=0 && R<rc && C<rc && grid1[R][C]=='*' )
                {
                    cnt++;
                }
            }
            if(flag==0)grid2[i][j]=cnt+'0';
            else grid1[i][j]=cnt+'0';
        }
        if(flag==0) rep(i,rc)printf("%s\n",grid2[i]);
        else  rep(i,rc)printf("%s\n",grid1[i]);
    }
    return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 » Mon Oct 21, 2013 9:40 pm

Input:

Code: Select all

3

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

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

8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.x...
xxxxx...
AC output:

Code: Select all

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

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

001**..*
0013..*.
0001*...
00011...
00001...
00123*..
001**.*.
00123*..
Check input and AC output for thousands of problems on uDebug!

hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

Re: 10279 - Mine Sweeper

Post by hello » Tue Oct 22, 2013 6:20 pm

Successfully pass your test cases...Still WA.....

Code: Select all

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#define zero(arr) memset(arr,0,sizeof(arr));
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,k) for(int i=0;i<n;i=i+k)

#define VI vector<int>
#define VVI vector< VI >
#define VIit VI::iterator

#define pb(a) push_back(a)
#define SI(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SLLD(a) scanf("%lld",&a)
#define SLLU(a) scanf("%llu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

using namespace std;

int dirR8[]= {0,-1,-1,-1,0,1,1,1};
int dirC8[]= {1,1,0,-1,-1,-1,0,1};
int dirR4[]= {0,-1,0,1};
int dirC4[]= {1,0,-1,0};
char grid1[11][11];
char grid2[11][11];
int cnt;

int main()
{
   // freopen("in.txt","r",stdin);
    int cases;
    SI(cases);
    int sp=0;
    while(cases--)
    {
        int flag=0;
        int rc;
        if(sp)printf("\n");
        sp=1;
        SI(rc);
        getchar();
        rep(i,rc)gets(grid1[i]);
        rep(i,rc)rep(j,rc){
            cin>>grid2[i][j];
            if(grid2[i][j]!='.' && grid1[i][j]=='*'){flag=1;grid2[i][j]='.';}
            }

        rep(i,rc)rep(j,rc)if(grid2[i][j]!='.')
        {
            cnt=0;
            rep(k,8)
            {
                int R=i+dirR8[k];
                int C=j+dirC8[k];
                if(R>=0 && C>=0 && R<rc && C<rc && grid1[R][C]=='*' )
                {
                    cnt++;
                }
            }
            if(flag==0)grid2[i][j]=cnt+'0';
            else grid1[i][j]=cnt+'0';
        }
        if(flag==0) rep(i,rc)printf("%s\n",grid2[i]);
        else  rep(i,rc)printf("%s\n",grid1[i]);
    }
    return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 » Tue Oct 22, 2013 10:27 pm

Change the way you parse the input. Try:

Code: Select all

1

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

Code: Select all

001**22*
0013..*.
0001*...
00011...
00001...
00123*..
001**.*.
00123*..
Check input and AC output for thousands of problems on uDebug!

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

Re: 10279 - Mine Sweeper

Post by hoimo » Tue Dec 03, 2013 5:59 pm

Plz help me. I cant understand why its WA?

Code: Select all

#include<stdio.h>

int main()
{
    int m, n, i, j, cnt[150], pnt, ans[11][11], k, l, flg;
    char str[11][11], prnt[11][11];

    scanf("%d", &n);
    while( n-- )
    {
        printf("\n");
        scanf("%d",&m);
        for( i=0; i<m; i++ )
            scanf("%s",str[i]);
        for( i=0; i<m; i++ )
            scanf("%s",prnt[i]);

        flg=0;
        pnt = 0;
        for( i=0; i<m; i++ )
        {
            for( j=0; j<m; j++ )
            {
                if( str[i][j] == '*' )
                {
                    ans[i][j] = -1;
                    cnt[pnt] = i;
                    pnt++;
                    cnt[pnt] = j;
                    pnt++;
                    if( prnt[i][j] == 'x' || prnt[i][j] == 'X' )
                        flg=1;
                }
                else
                    ans[i][j] = 0;
            }
        }

        for( i=0,j=1; j<pnt; i=i+2,j=j+2 )
        {
            k = cnt[i];
            l = cnt[j];

            if( (k-1)>=0 && (l-1)>=0 && ans[k-1][l-1]!=-1 )
                ans[k-1][l-1]++;
            if( (k-1)>=0 && ans[k-1][l]!=-1 )
                ans[k-1][l]++;
            if( (k-1)>=0 && (l+1)<m && ans[k-1][l+1]!=-1 )
                ans[k-1][l+1]++;


            if( (l-1)>=0 && ans[k][l-1]!=-1 )
                ans[k][l-1]++;
            if( (l+1)<m && ans[k][l+1]!=-1 )
                ans[k][l+1]++;


            if( (k+1)<m && (l-1)>=0 && ans[k+1][l-1]!=-1 )
                ans[k+1][l-1]++;
            if( (k+1)<m && ans[k+1][l]!=-1 )
                ans[k+1][l]++;
            if( (k+1)<m && (l+1)<m && ans[k+1][l+1]!=-1 )
                ans[k+1][l+1]++;
        }

        for( i=0; i<m; i++ ) {
            for( j=0; j<m; j++ ) {
                if( prnt[i][j] == 'x' || prnt[i][j] == 'X' ) {
                    if( ans[i][j] != -1 )
                        printf("%d",ans[i][j]);
                    else
                        printf("*");
                }
                else {
                    if( ans[i][j]==-1 && flg==1 )
                        printf("*");
                    else
                        printf(".");
                }
            }
            printf("\n");
        }
    }
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 » Tue Dec 03, 2013 11:49 pm

Don't print a blank line at the start of the output.
Check input and AC output for thousands of problems on uDebug!

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

Re: 10279 - Mine Sweeper

Post by hoimo » Sun Dec 08, 2013 6:44 am

Thnx. I got AC.

Post Reply

Return to “Volume 102 (10200-10299)”