447 - Population Explosion

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

Moderator: Board moderators

Ghust_omega
Experienced poster
Posts: 115
Joined: Tue Apr 06, 2004 7:04 pm
Location: Venezuela

Post by Ghust_omega »

Thanks !!! Minilek this i/o was very useful , with this i see where is wrong, and I got AC, but P.E. :( my I/O is almost the same as yours only for one '\n' and i dont figure out how can avoid the P.E. please someone that helps
Thanks in advance
Keep posting!!! :)
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

Post by CodeMaker »

:D HI , I got P.E. at first then I printed a newline after each test case including the last one and got Acc..... :-?
Jalal : AIUB SPARKS
phoenix7
New poster
Posts: 5
Joined: Fri Oct 07, 2005 11:21 pm
Location: Tehran, IRAN
Contact:

Post by phoenix7 »

I think my program should not get WA! I've yours about what the output should be. and I've tried to fix it but still, I get WA. can anyone read my code please.

Code: Select all

#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <algorithm>
using namespace std;
#define show(x)			cout << #x << " = " << x << endl
#define FOR(i, n)		for(int i = 0; i < n; i ++)


int main() {
	#ifndef ONLINE_JUDGE
	freopen("PopulationExplosion.in", "r", stdin);
	#endif

	char buf[100];

	int t;
	cin >> t;
	int tt = 0;
	while(t --) {
		//show(tt);
		if(tt ++)
			cout << endl;

		int y;
		cin >> y;
		cin.getline(buf, 100);

		char b[20][20];

		FOR(i, 20)
			FOR(j, 20)
				b[i][j] = ' ';

		while(cin.getline(buf, 100), buf[0]) {
			string line = buf;
			istringstream iss(line);
			//show(line);

			int r, c;
			iss >> r >> c;
			b[r-1][c-1] = 'o';
		}

		FOR(k, y) {
			cout << "*******************" << endl;

			char next[20][20];
			FOR(i, 20)
				FOR(j, 20)
					next[i][j] = ' ';

			FOR(i, 20) {
				FOR(j, 20)
					cout << b[i][j];
				cout << endl;
			}

			FOR(i, 20) {
				FOR(j, 20) {
					int nb = 0;
					for(int ii = i-1; ii <= i+1; ii ++)
						for(int jj = j-1; jj <= j+1; jj ++) {
							if(!(ii == i && jj == j) && ii >= 0 && ii < 20 && jj >= 0 && jj < 20 && b[ii][jj] == 'o')
								nb ++;
						}

					if(b[i][j] == ' ' && nb == 3)
						next[i][j] = 'o';
					else if(b[i][j] == 'o' && (nb < 2 || nb > 3))
						next[i][j] = ' ';
					else
						next[i][j] = b[i][j];
				}
			}

			FOR(i, 20)
				FOR(j, 20)
					b[i][j] = next[i][j];
		}
		cout << "*******************" << endl;
	}

	return 0;
}
-- Mohammad
do you Python?
TimeString
New poster
Posts: 26
Joined: Mon Nov 13, 2006 3:53 am

P.E.??

Post by TimeString »

Ghust_omega wrote:Thanks !!! Minilek this i/o was very useful , with this i see where is wrong, and I got AC, but P.E. :( my I/O is almost the same as yours only for one '\n' and i dont figure out how can avoid the P.E. please someone that helps
Thanks in advance
Keep posting!!! :)
Hey, be careful the day it gives might be 0, which should only print a line contains 20 '*'.
And, don't delete spaces after the last 'O'. After I change this condition, I got ACc.

P.S. I don't print a blank line after the last case.
shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

WHY PE in 447 please help....

Post by shakil »

please please help..............

Code: Select all


Cut after AC

Last edited by shakil on Fri Apr 13, 2007 10:10 am, edited 1 time in total.
SHAKIL
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Search your problem first. Don't open a new thread if there is one already. This problem already has many threads.
Ami ekhono shopno dekhi...
HomePage
shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

Post by shakil »

Jan , can you expline why i don't open a new thread if there is one already , what's the problem. Thanks for your help.
SHAKIL
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Read the description about any volume. For volume 1...
All about problems in Volume I. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Because if there are many threads for a single problem, it would be harder to find useful information from the threads. See the threads in volume 1. There are 31 pages, did you ever check page 31? why?
For some problems there are more than 30 threads for each. If you need a desired information you have to check all of them.

That's why there should be one thread for one problem.
Ami ekhono shopno dekhi...
HomePage
shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

Post by shakil »

Thanks Jan, for your expline. I shall try to maintain your opinion.
SHAKIL
Post Reply

Return to “Volume 4 (400-499)”