## 457 - Linear Cellular Automata

Moderator: Board moderators

masti
New poster
Posts: 3
Joined: Mon Aug 05, 2002 11:03 pm

### 457 - Linear Cellular Automata

I am trying to solve the linear cellular automata problem. This is my code I get a wrong answer reply and I don't really know what's wrong about it. Thanks for help

Code: Select all

``````program automata(input,output);

var
T1,T2:array [1..40] of byte;
DNA:array [0..9] of byte;
i,z:integer;

procedure print(var T:array of byte);

var
i:integer;

begin
for i:=0 to 39 do
begin
case T[i] of
0:write(' ');
1:write('.');
2:write('x');
3:write('W');
end;
end;
end;

begin
while not eof(input) do begin
for i:=1 to 10 do
T1[20]:=1;
print(T1);
writeln;
for i:=1 to 49 do
begin
T2[1]:=DNA[T1[2]+T1[1]];
T2[40]:=DNA[T1[39]+T1[40]];
for z:=2 to 39 do
T2[z]:=DNA[T1[z+1]++T1[z]+T1[z-1]];
print(T2);
writeln;
for z:=1 to 40 do
T1[z]:=T2[z];
end;
end;
end.``````

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm
I'm not familiar in pascal , but consider this , it's multiple input case , so everytime you loop to the next input , you must normalize the variable that you declare , I got PE in this problem , but I see someone who get AC and when I see his code, his output produce 1 more blank line than me

hope this would help

Kentaro
New poster
Posts: 19
Joined: Thu Feb 05, 2004 4:41 am
I'm trying to solve this too but in C++. I'm not sure what I'm doing wrong, the code seemed so easy... Please help.
EDIT: Fixed the mixed-up loop indexes (inside a for loop over the variable i I had other for loops over the variable i. That'd be bad) but still WA...

[cpp]
using namespace std;
#include <iostream>
#include <string>
#include <sstream>

const int DNA_SIZE = 10;
const int DISH_SIZE = 40;
const int FIRST_DISH = 20;
const int DAYS = 50;

int program[DNA_SIZE];
int dish[DISH_SIZE];
int new_dish[DISH_SIZE]; // temporary holder for next day's values

int main()
{
string in_line;
while (getline(cin, in_line))
{
istringstream input(in_line);
// Initialize the dish
for (int i = 0; i < DISH_SIZE; i++)
{
if (i == FIRST_DISH - 1) dish = 1;
else dish = 0;
new_dish = 0;
}

for (int i = 0; i < DNA_SIZE; i++) input >> program;

// Run the simulation
for (int i = 0; i < DAYS; i++)
{
// Write today's values from the dish
for (int j = 0; j < DISH_SIZE; j++)
{
switch (dish[j])
{
case 0: cout << ' '; break;
case 1: cout << '.'; break;
case 2: cout << 'x'; break;
case 3: cout << 'W'; break;
}
}
cout << '\n';

// Handle the left end first, it is special.
int left_sum = dish[0] + dish[1];
new_dish[0] = program[left_sum];

for (int j = 1; j < DISH_SIZE - 1; j++)
{
int sum = dish[j - 1] + dish[j] + dish[j + 1];
new_dish[j] = program[sum];
}

// Handle the right end last, it is special.
int right_sum = dish[DISH_SIZE - 1] + dish[DISH_SIZE - 2];
new_dish[DISH_SIZE - 1] = program[right_sum];

// Copy tomorrow's values into the dish
for (int j = 0; j < DISH_SIZE; j++) dish[j] = new_dish[j];
}
cout << '\n';
}
}
[/cpp]
Computer Science is no more about computers than Astronomy is about telescopes.
-- E. W. Dijkstra

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am
I copied your program and tried to test it. But the program crashed and I just used the data mentioned in the problem statement.

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:
Kentaro:

You're not reading the input correctly. The first line is the number of test cases; the second is empty; the third is the first test case; the fourht is empty; etc.

Kentaro
New poster
Posts: 19
Joined: Thu Feb 05, 2004 4:41 am
Okay. I'll fix what I'm doing to read the input that way and see what happens. But it wouldn't have hurt for them to specify that more clearly somewhere...
Computer Science is no more about computers than Astronomy is about telescopes.
-- E. W. Dijkstra

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:
I think it does:
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

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

For an input like

Code: Select all

``````3

3 3 3 3 3 3 3 3 3 3

0 1 2 0 1 3 3 2 3 0

0 0 0 0 0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bbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
``````
b represents a blank as in the problem statement because that's easier to read. In the program you submit, there should be a real blank!

Kentaro
New poster
Posts: 19
Joined: Thu Feb 05, 2004 4:41 am
Well, when I read the problem (this was some weeks ago) it didn't seem to say anything about how to handle the multiple input. If it had, I would have gotten AC a lot sooner.

Well, I got my AC so no more complaints from me. I'll have to see about reading problems even more carefully from now on.
Computer Science is no more about computers than Astronomy is about telescopes.
-- E. W. Dijkstra

TheVelho
New poster
Posts: 2
Joined: Tue Aug 28, 2007 5:55 pm
Hi, I don't understand why I'm getting a PE. Here is my code :

Code: Select all

``````#include<stdio.h>

int DNA[10];
int c[50][40];

void compute_line(int i) {
int j;

c[i+1][0] =  DNA[c[i][0]  + c[i][1]];
c[i+1][39] = DNA[c[i][38] + c[i][39]];

for(j = 1; j < 39; j++)
c[i+1][j] = DNA[c[i][j-1] + c[i][j] + c[i][j+1]];

return;
}

int main() {
int n, i, j;

scanf("%d", &n);
printf("\n");

while(n--)
{
/* init */

scanf("%d %d %d %d %d %d %d %d %d %d",
&DNA[0], &DNA[1], &DNA[2], &DNA[3], &DNA[4],
&DNA[5], &DNA[6], &DNA[7], &DNA[8], &DNA[9]);
printf("\n");

/* computing */

for(j = 0; j< 40; j++)
c[0][j] = 0;
c[0][19] = 1;

for(i = 0; i < 49; i++)
compute_line(i);

/* printing */

for(i = 0; i < 50; i++) {
for(j = 0; j < 40; j++) {
switch(c[i][j]) {
case 1: printf("."); break;
case 2: printf("x"); break;
case 3: printf("W"); break;
default: printf(" ");
}
}
printf("\n");
}
printf("\n");
}

return 0;
}``````
A sample would be like

Code: Select all

``````2

0 1 2 3 0 1 2 3 0 1

.
...
[blah blah blah]
.. WW   WW.xx   .. WW   xx xx

0 2 1 3 0 2 1 3 0 2

.
xxx
[blah blah blah]
Wxx . xx.x.x.xx WxW . xxW xx.x.x.xx

``````

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
You're printing extra 2 blank lines at the very first line..
And you're also printing 1 more blank line between each case..
See WR's output..

TheVelho
New poster
Posts: 2
Joined: Tue Aug 28, 2007 5:55 pm
I finally got it working, after a few thousands of tries... Sorry for the noise.

There should be one blank line between each bloc, and none at the end.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Contact:

### Re: Linear Cellular Automata 457

why WA??
plz someone help.

Code: Select all

``````   #include<stdio.h>

int  main()

{

int i,j,c,a,ncase;
int  DNA[12];
int dish[42],temp[42];

scanf("%d\n\n",&ncase);

while(ncase>0)
{

for(i=0;i<10;i++)

{
scanf("%d",&DNA[i]);

}

for(i=0;i<=41;i++)

{
dish[i]=0;

}

dish[20]=1;

for(i=0;i<=40;i++)

{
temp[i]=dish[i];

}

printf("                   .                   \n");

for(j=2;j<=50;j++)

{
for(i=1;i<=40;i++)

{
c=dish[i-1]+dish[i]+dish[i+1];

a=DNA[c];
if(a==0)
printf(" ");
else if(a==1)
printf(".");
else if(a==2)
printf("x");
else if(a=3)
printf("W");

temp[i]=a;

}
if(j<50 || i<40)
printf("\n");

for(i=1;i<=40;i++)

{
dish[i]=temp[i];

}

}

if(ncase>1)
printf("\n\n");

ncase--;
}

return 0;

}
``````
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359

anan_brish
New poster
Posts: 1
Joined: Thu Nov 05, 2009 5:50 pm

### Re: Linear Cellular Automata 457

can anyone just compile my code for this problem?
i think itz correct,but still getting WA..working for hours on it.help plz..

Code: Select all

``````
#include<stdio.h>

char ch[40];
char ch1[40];
int dna[10];
char pr[100][40*50];

char det(int a);
int detchar(char ch);

int main(void){
int cas,j,k,i;
scanf("%d",&cas);
if(cas>0){
printf("\n");
j=0;
while(j<cas){
int cn=0;

for(k=0;k<10;k++){
scanf("%d",&dna[k]);
}
for(k=0;k<40;k++)
{
if(k==19)
ch[k]='.';
else
ch[k]=' ';
ch1[k]=' ';
}
for(k=0;k<40;k++,cn++){
pr[j][cn]=ch[k];
}
i=0;
while(i<49){
for(k=0;k<40;k++,cn++)
{
ch1[k]=det(k);
pr[j][cn]=ch1[k];
}
for(k=0;k<40;k++)
ch[k]=ch1[k];
i++;
}
j++;
if(j!=cas)
{
printf("\n");
}
else{
int cas2,lc,ct,line=1;
for(cas2=0;cas2<cas;cas2++){
for(ct=0,lc=0;lc<40*50;lc++,ct++){
printf("%c",pr[cas2][lc]);
if(ct==39){
printf("\n");
line++;
ct=-1;
}
}
if(cas2!=cas-1)
printf("\n");
}
}
}

}
return 0;
}

char det(int a){
int m;
char c;

if(a-1<0)
ch[a-1]=' ';
if(a+1==40)
ch[a+1]=' ';

m=detchar(ch[a-1])+detchar(ch[a])+detchar(ch[a+1]);

switch(dna[m]){
case 0:{c=' ';break;}
case 1:{c='.';break;}
case 2:{c='x';break;}
case 3:{c='W';break;}
default:{c=' ';break;}
}

return c;
}

int detchar(char ch){
int m;

switch(ch){
case ' ':{ m=0; break;}
case '.':{ m=1; break;}
case 'x':{ m=2; break;}
case 'W':{ m=3; break;}
default :{ m=0;}
}
return m;
}

``````