339 - SameGame Simulation

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

Moderator: Board moderators

ashutoshkorde
New poster
Posts: 6
Joined: Mon May 05, 2003 1:48 pm

339 - SameGame Simulation

Post by ashutoshkorde »

i've got the program working but the only problem is

do they require the output after they input all the grids and enter the final 0, 0 or they want the final grid to be displayed after each and every grid's 0,0 is encounter ???? :cry:
Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Post by Red Scorpion »

After we encounter the "0, 0", we must check 2 condition:
1. If the game won, we must output : "Game Won".
2. Otherwise you must output the final configuation of that game.

Hope this helps. :lol:
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

Well ashutoshkorde, that doesn't realy matter, because the judge first lets you complete the program, collecting all output in one big text file, and then checks this file to determine the verdict. So it's realy up to you how and in which order you read input, process data and write output, as long as the resulting output file is correct.
(The actual situation is a little more complicated, because the running program can be interrupted by errors, but that is the general idea).
ashutoshkorde
New poster
Posts: 6
Joined: Mon May 05, 2003 1:48 pm

Post by ashutoshkorde »

hey joey thanks a lot but then i feel that the program itself is wrong somewhere... i'll get working on it, thanks a lot
raul444
New poster
Posts: 1
Joined: Mon May 19, 2003 5:07 pm

339 Wrong Anwer

Post by raul444 »

I wrote an implementation for 339 problem. I tried to submit it but the Onlid Jutge answers me Wrong Answer. For this reason, I want a sample output from a program that the online Judge accepts. Thanks.[/cpp]
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Why did you not search this forum before posting this ? This problem has our thread - look at it ...

DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver

Post by minskcity »

Can anybody give me some critical inputs/outputs or find a bug in my code? I've already got more than 10 WA :cry:

Code: Select all

#include <iostream>
#include <vector>
using namespace std;

vector < vector < int > > data;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

bool good(int x, int y, int num){
	return x > -1 && y > -1 && x < (int)data.size() && y < (int)data[x].size() && data[x][y] == num;
}

void dfs(int x, int y, int num){
	if(!good(x, y, num)) return;
   data[x][y] = -1;
   for(int d = 0; d < 4; d++) dfs(x + dx[d], y + dy[d], num);
}

int m, n;

int main(){

	int test = 1;
	while(cin >> m >> n && m && n){
   	data.clear();
   	data.resize(n, vector < int > (m));
      for(int i = 0; i < m; i++)
      	for(int j = 0; j < n; j++) cin >> data[j][i];

      while(cin >> m >> n && (m || n)){
      	m--, n--;
         if(m < 0 || n < 0 || n >= (int)data.size() || m >= (int)data[n].size()) continue;
         bool f = false;
         for(int d = 0; d < 4; d++) f |= good(n + dx[d], m + dy[d], data[n][m]);
         if(!f) continue;

         dfs(n, m, data[n][m]);

         for(unsigned i = 0; i < data.size(); i++)
         	for(int j = data[i].size() - 1; j >= 0; j--)
            	if(j < (int)data[i].size() && data[i][j] == -1) data[i].erase(data[i].begin() + j);

         for(int i = data.size() - 1; i >= 0; i--)
         	if(i < (int)data.size() && data[i].empty()) data.erase(data.begin() + i);

      }

      cout << "Grid " << test++ << "." << endl;
      if(data.empty()) cout << "    Game Won" << endl;
      else{
      	cout << endl;
      	int mx = 0;
         for(unsigned i = 0; i < data.size(); i++) mx >?= (int)data[i].size();
         for(int j = mx - 1; j >= 0; j--){
         	cout << "   ";
         	for(unsigned i = 0; i < data.size(); i++)
            	if(j < (int)data[i].size()) cout << " " << data[i][j];
               else cout << "  ";
            cout << endl;
         }
      }
      cout << endl;

   }

	return 0;
}
abhijit
New poster
Posts: 12
Joined: Mon May 24, 2004 2:13 pm

can't understand sample i/o

Post by abhijit »

I can't understand the sample i/o for this problem.
According to me the output for the 1st sample input is :

Code: Select all

      3
      3   1
    3 5 2 2

What's wrong in my understanding of the problem ?
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

The input is given upside down.. when I was reading this problem, it took me a while to realize too..
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Can anybody send me some test cases....

Thanks.
Ami ekhono shopno dekhi...
HomePage
minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver

Post by minskcity »

I've figured out that I actually had a presentation error - they want spaces printed so that the size of the game state is always the same, even if most of the numbers are gone...
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

minskcity wrote:I've figured out that I actually had a presentation error - they want spaces printed so that the size of the game state is always the same, even if most of the numbers are gone...
I still don't understand. Can u help me about this?? I want to know about the output pattern. Anybody can help??

Thanks.
Ami ekhono shopno dekhi...
HomePage
minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver

Post by minskcity »

for the input:

Code: Select all

3*3*3
2*3*3
output (after clicking on 3) should be:

Code: Select all

*********
****2****
where '*' stays for blank space. If you don't print those blanks, you will get WA.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Thankx minskcity, but I m still getting WA.
Can u tell me what is the output for the following input set...
( If u don't mind please use * instead of space)

Input:

Code: Select all

4 4
1 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
1 2
1 1
0 0

1 1
0
1 1
0 0

2 3
0 0 0
0 2 2
2 3
2 2
0 0

2 3
0 0 0
0 2 2
2 3
1 1
0 0

0 0
And my code gives the following output

Output:

Code: Select all

Grid 1.
***********
***********
***********
****1******

Grid 2.
****0

Grid 3.
****0****
****0*0*0

Grid 4.
    Game Won
I use * instead of space. Any tricky cases? :-?
Ami ekhono shopno dekhi...
HomePage
minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver

Post by minskcity »

My AC program outputs

Code: Select all

Grid 1.
***********
***********
***********
****1******

Grid 2.
****0

Grid 3.
****0****
****0*0*0

Grid 4.
****Game Won
for your inputs.
Post Reply

Return to “Volume 3 (300-399)”