572 - Oil Deposits

All about problems in Volume 5. 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
theharshest
New poster
Posts: 20
Joined: Thu Jan 17, 2008 10:47 pm
Location: India

Re: 572 WA :-(

Post by theharshest » Tue Jan 13, 2009 5:15 pm

WA for the following code.. Please help..

Code: Select all

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<stack>
using namespace std;

int main()
{
	int m,n,c=0,x,y;
	vector< vector<bool> > vb;
	vector<string> v;
	string st;
	pair<int,int> pii,tmp1,tmp2;
	stack< pair<int,int> > s;

	cin>>m;	

	while(m!=0)
	{
		c=0;
		cin>>n;
		v.clear();
		vb.resize(m);

		for(int i=0;i<vb.size();i++)
			vb[i].resize(n,0);

		
		for(int i=0;i<m;i++)
		{
			
				cin>>st;
				v.push_back(st);
			
		}
		
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{	
				//cout<<i<<" "<<j<<endl;					
				//cout<<"hi"<<endl;
				if(v[i][j]=='@' && vb[i][j]==0)
				{
					pii.first=i;
					pii.second=j;

					s.push(pii);

					while(!s.empty())
					{
						tmp1=s.top();
						s.pop();
						x=tmp1.first;
						y=tmp1.second;
						vb[x][y]=1;		
						
	    if(x-1>=0 && v[x-1][y]=='@' && vb[x-1][y]==0)
            {   
                tmp2.first=x-1;
                tmp2.second=y;
                s.push(tmp2);                           
            }
            if(y-1>=0 && v[x][y-1]=='@' && vb[x][y-1]==0)
            {   
                tmp2.first=x;
                tmp2.second=y-1;
                s.push(tmp2);                           
            }
            if(x-1>=0 && y-1>=0 && v[x-1][y-1]=='@' && vb[x-1][y-1]==0)
            {   
                tmp2.first=x-1;
                tmp2.second=y-1;
                s.push(tmp2);                           
            }
            if(x+1<m && y+1<n && v[x+1][y+1]=='@' && vb[x+1][y+1]==0)
            {   
                tmp2.first=x+1;
                tmp2.second=y+1;
                s.push(tmp2);                           
            }
            if(x+1<m && v[x+1][y]=='@' && vb[x+1][y]==0)
            {   
                tmp2.first=x+1;
                tmp2.second=y;
                s.push(tmp2);                           
            }
            if(y+1<n && v[x][y+1]=='@' && vb[x][y+1]==0)
            {   
                tmp2.first=x;
                tmp2.second=y+1;
                s.push(tmp2);                           
            }
            if(x+1<m && y-1>=0 && v[x+1][y-1]=='@' && vb[x+1][y-1]==0)
            {   
                tmp2.first=x+1;
                tmp2.second=y-1;
                s.push(tmp2);                           
            }
            if(x-1>=0 && y+1<n && v[x-1][y+1]=='@' && vb[x-1][y+1]==0)
            {   
                tmp2.first=x-1;
                tmp2.second=y+1;
                s.push(tmp2);                           
            }
			
					}
			c++;
				}
			}		
		}
		cout<<c<<endl;
		cin>>m;
	}

}
"if u r goin thru hell, keep goin"

back_tracker
New poster
Posts: 9
Joined: Sun Jun 19, 2011 12:03 am

Re: 572 WA :-(

Post by back_tracker » Thu Jul 21, 2011 3:30 pm

easy problem, solve it using DFS

Hi,

This is an automated response from UVa Online Judge.

...Your submission with number 9066985 for the problem 572 - Oil Deposits has succeeded with verdict Accepted.

Congratulations! Now it is time to try a new problem.

Best regards,

The UVa Online Judge team

:P :P :P :P :P :P

User avatar
@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 572 WA :-(

Post by @ce » Fri Dec 28, 2012 9:30 am

Getting WA...some test case plzzz

Code: Select all

AC
Last edited by @ce on Sat Dec 29, 2012 3:45 pm, edited 1 time in total.
-@ce

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

Re: 572 WA :-(

Post by brianfry713 » Sat Dec 29, 2012 12:45 pm

Code: Select all

2 1
*
@
0 0
Check input and AC output for thousands of problems on uDebug!

User avatar
@ce
Learning poster
Posts: 71
Joined: Mon May 28, 2012 8:46 am
Location: Ranchi, India

Re: 572 WA :-(

Post by @ce » Sat Dec 29, 2012 3:45 pm

Thanks brianfry713, i got my mistake.
-@ce

rifath_csedu
New poster
Posts: 2
Joined: Fri Aug 10, 2012 2:18 pm

Re: 572 WA :-(

Post by rifath_csedu » Fri Mar 22, 2013 2:27 pm

I got WA in this problem... please give some test case :( :(

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

Re: 572 WA :-(

Post by brianfry713 » Fri Mar 22, 2013 10:17 pm

Input:

Code: Select all

9 1
@
@
@
@
*
*
*
@
*
10 6
*****@
@@@@*@
*@*@*@
**@**@
@@@@@*
**@@@@
*@@***
*@**@@
****@@
@@*@@*
7 6
@*@@**
**@@@@
@**@*@
@@*@**
*@***@
**@@**
*@*@@*
5 5
***@*
**@*@
@@@*@
*@*@@
****@
8 1
@
@
*
*
*
@
@
*
4 6
@*@@**
@****@
**@*@*
**@***
9 9
*@*@*@*@@
***@@@*@@
@@*@*@***
@@@@*@@*@
@*@@@**@*
@**@*@***
***@**@@*
*@@*@**@*
@@**@@@@*
4 5
*@@@*
@*@**
*@*@*
**@@*
7 9
@*@**@@@*
*@******@
@*@@***@*
****@@**@
**@@*@*@*
**@*@*@@@
*****@@@@
1 4
****
1 4
@**@
3 3
@@@
@@@
@@*
2 10
@@@**@@*@*
@*@@**@**@
4 10
@**@*@@**@
***@@**@@@
*@@@*@*@**
@*@*@@*@**
1 9
@@*@*@@@@
9 8
**@**@@@
@@@@@@*@
*@@@*@**
@*@@@*@*
*@@@**@*
*@*****@
**@@@*@@
*@@**@@@
*@@@*@*@
4 4
*@@@
@*@*
@@@@
@*@@
4 1
@
@
@
*
1 8
*@***@@@
7 5
*@***
**@**
***@*
*@***
*@@@*
*@**@
*@***
1 3
@@@
7 6
*@@@@@
**@**@
***@@@
@@***@
@**@*@
@**@**
**@*@*
2 10
@@**@@***@
@***@**@@@
6 4
*@@*
*@*@
@*@*
@@**
@**@
@**@
3 7
*@*@*@@
@@*@**@
@*@***@
3 8
@***@***
@*@@@@@@
@***@*@*
10 8
***@**@@
@@@**@@*
**@**@*@
@*@@***@
@@@@@@@@
*@@@*@@@
*@**@@*@
@*@*****
@**@@@@*
@@*****@
2 4
*@**
@*@*
6 1
@
*
*
@
*
@
2 7
@*@***@
@*@*@*@
5 3
**@
@@@
*@@
@**
**@
1 10
@@@**@@***
1 1
*
4 5
@@*@*
****@
@@*@@
@@@@*
9 10
@@@*@@@***
***@@@**@*
@@*@@*@@*@
@*@@@*@@@@
****@***@@
*@@@@@@*@*
*@@**@@*@@
*@@@*@*@*@
@@@@**@*@@
10 1
*
@
@
@
@
*
*
@
*
*
10 7
****@**
@***@@*
*@@****
@***@@@
*@@*@*@
@@*@@@*
@**@***
*@***@@
*@@**@@
*@@*@**
8 7
**@@*@*
@***@@@
@*@@@**
@@*@***
*@*@**@
@**@@@@
@@@@*@*
@@@@@**
3 9
@*@******
@@@*@@*@@
@*@**@*@*
8 5
*@*@*
**@@@
@@@@*
@@*@@
**@@*
***@*
@****
@@@*@
4 1
*
@
*
@
8 1
*
@
*
@
*
*
@
@
4 9
*@@**@*@@
*@*@@@*@*
*@@*@**@*
@@**@@@**
3 7
@@@@@@*
@**@@@@
*@@*@**
1 4
@*@@
9 7
@*@**@*
***@**@
*@@*@*@
*@**@@@
*@@**@@
@@**@**
*@@@@@*
@****@*
*@*@**@
2 1
@
*
5 8
@**@@*@@
@@@@**@@
@**@@@**
@@@@**@*
******@*
1 8
*@**@*@@
9 7
@**@**@
@**@@@*
****@@*
@****@@
*@@*@@*
**@@@*@
@**@*@*
****@@*
*@****@
2 6
@@*@@*
*@@@@@
9 6
***@@*
@***@@
@@@**@
*@@@@*
@@@@@*
**@@@*
@@@***
****@@
@@*@@*
9 3
*@*
**@
@@@
@*@
***
@@@
@*@
@@@
@*@
5 1
@
*
*
@
@
3 7
@@@@***
@@@@**@
@**@***
1 10
*@*@@*@@**
8 1
@
*
@
@
@
*
@
*
8 5
**@@@
*****
*@*@*
@@@**
@*@@*
@****
@*@@*
@@@@*
2 4
@***
*@@@
3 4
**@@
@@**
*@@@
8 9
@@@@@*@@@
******@*@
@@@@@@**@
@*@*@**@*
*@**@@**@
@@**@**@*
*****@@*@
*@*@*****
9 6
**@***
*@**@@
@*@@*@
*@****
*@@@@*
@**@@@
@*@*@@
*@**@*
***@*@
9 2
@*
@@
*@
*@
@*
@@
@@
*@
**
3 8
@**@*@@@
@@@**@*@
@*@@@@**
9 10
*@*@@@@@@*
@@**@*@@**
@*@****@@@
**@@@*@@*@
***@@**@*@
@@*@*@*@**
*@**@*@***
*@*@@*@*@*
*@*@@@@@**
7 2
*@
*@
*@
*@
*@
@@
*@
6 7
*@@@@@@
@@*@*@@
*@@*@@*
*@@***@
*****@*
*@@*@*@
8 5
@**@@
*@*@*
@@@*@
*@@@*
@@@@@
*@**@
@*@@@
@*@@@
7 6
@**@**
@*@@*@
@***@*
**@**@
@@*@@@
@@@***
@*@@@@
5 1
*
*
*
@
@
6 2
*@
@*
@@
@@
**
@*
2 4
@@*@
@*@@
9 4
@*@@
***@
**@@
*@@@
**@@
@@@@
@**@
****
@***
3 5
@**@*
*@@*@
**@*@
2 8
@@***@@*
@*@****@
2 7
@*@@*@*
@@@@*@*
6 10
@**@@**@@@
*@@@*@**@@
***@@**@@*
*@@@@@**@*
*@*@@*@*@*
@@@*@@@*@*
4 7
*@*@@@*
*@*****
@*@*@@*
****@@@
10 4
*@**
@@*@
***@
*@**
**@@
@***
@@**
@@@@
****
*@*@
3 7
@*@*@@*
*@*@*@*
*@@@@@@
10 8
****@***
@@****@@
**@@@*@@
*@@*@@**
*@@**@@*
@@******
*@******
**@***@@
**@**@@*
@**@*@*@
3 1
*
@
@
4 7
*******
*@@***@
@*@*@@@
@*@*@**
2 5
@***@
@@@**
4 1
@
@
*
@
2 10
@*@@***@*@
**@*******
9 2
@@
**
@@
**
@*
@@
@*
**
@*
4 6
@***@@
***@@@
@**@@@
*@@*@@
8 2
**
@@
@*
@*
@@
**
@*
@@
9 2
*@
**
@@
*@
@*
@*
**
@*
@@
1 1
@
1 2
*@
7 1
@
@
*
*
@
*
@
9 10
@*@@@***@*
*@@*@@@***
*@*@*@@*@*
**@***@*@*
@**@*@@**@
@@@@@*@@@*
@*@@****@@
@**@*@@@@*
@@*@@@**@@
3 9
*@*@*@@@@
@*@@@@@@@
*@**@**@@
9 10
@@*@*@@*@@
@@*@**@*@*
*@@@****@@
*@@@**@**@
***@*@****
@@@@@*@*@@
@*@@**@@@*
@*@*****@*
@**@*@****
8 6
@@@@*@
@@*@**
@*@*@@
@@*@**
@@@*@@
*@@*@*
*@*@**
**@*@@
10 10
@***@*@@@@
@*@@@*@***
*@@@*@*@@*
**@@@@*@@*
@*****@***
*@@***@@*@
*@**@@**@@
***@@@*@@@
****@@*@@@
*@*@**@***
9 10
@@@@@*@@@*
***@*@@*@*
**@**@@@**
@**@****@*
**@@**@@*@
*@@***@***
@****@*@@*
@*@@*@@*@*
******@*@*
4 9
@*@*@*@@@
@**@@*@**
*@@*@*@@@
@@**@@@@@
0 0
Ac output:

Code: Select all

2
3
4
1
2
4
3
1
1
0
2
1
3
2
3
1
1
1
2
2
1
3
3
2
2
2
1
1
3
4
2
2
0
2
1
2
3
1
3
3
2
3
1
1
2
3
1
1
3
4
1
3
2
2
2
3
3
2
1
1
4
1
1
1
2
1
2
1
2
1
2
1
3
1
2
2
2
3
6
1
4
1
2
2
2
4
4
2
2
3
1
1
3
2
1
4
2
3
3
1
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: 572 WA :-(

Post by hello » Fri Oct 18, 2013 9:32 pm

where's the problem;

Code: Select all

I got it

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 572 - Oil Deposits

Post by uDebug » Sat Apr 04, 2015 11:44 am

brianfry713,
Thanks for the great test cases!
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

fmmst
New poster
Posts: 2
Joined: Tue Jun 09, 2015 8:35 am

Re: 572 - Oil Deposits

Post by fmmst » Tue Jun 09, 2015 8:38 am

Why runtime error

Code: Select all

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
#include <stack>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;


void input();
void BFS(int index1,int index2);


char plot[102][102];
int row,clm;
int diraction1[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diraction2[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main()
{
    input();

    return 0;
}

void input()
{
    int i,j,oil_polot;
    while(scanf("%d %d",&row,&clm)!=EOF)
    {
        if(row+clm==0) break;
        getchar();
        oil_polot=0;
        memset(plot,0,sizeof(plot));

        for(i=0;i<row;i++)
            gets(plot[i]);

        for(i=0;i<row;i++)
            for(j=0;j<clm;j++)
                if(plot[i][j]=='@')
                {
                    oil_polot++;BFS(i,j);
                }

        printf("%d\n",oil_polot);
    }
}

void BFS(int  index1,int index2)
{
    int temp1,temp2,i;
    queue<int>Q;

    Q.push(index1); Q.push(index2);
    while(!Q.empty())
    {
        temp1=Q.front(); Q.pop(); temp2=Q.front();Q.pop();
        for(i=0;i<8;i++)
        {
            index1=temp1+diraction1[i];
            index2=temp2+diraction2[i];

            if(plot[index1][index2]=='@')
            {
                plot[index1][index2]='*';
                Q.push(index1); Q.push(index2);
            }
        }
    }
}
Last edited by brianfry713 on Fri Jun 19, 2015 6:33 am, edited 1 time in total.
Reason: Added code blocks

Post Reply

Return to “Volume 5 (500-599)”