Help wanted: 457 - Linear Cellular Automata

View previous topic View next topic Go down

CPP Help wanted: 457 - Linear Cellular Automata

Post by BIT0130-Shakkhor on Wed Jun 08, 2011 1:59 am

[You must be registered and logged in to see this link.] is actually an easy problem. But i really have no idea what went wrong. Please check this code and let me know.

Code:
#include <stdio.h>
#define LINES 50
#define DISHES 40

int DNA[10], dishes[DISHES][LINES];

void initialize()
{
   for(int i=0;i<DISHES;i++)
   dishes[i][0]=0;
   dishes[19][0]=1;
}

void generate()
{
   initialize();
   for(int i=1;i<LINES;i++)
   {
      dishes[0][i]=DNA[dishes[0][i-1]+dishes[1][i-1]];
      dishes[39][i]=DNA[dishes[38][i-1]+dishes[39][i-1]];

      for(int j=1;j<DISHES-1;j++)
      {
         dishes[j][i]=DNA[dishes[j][i-1]+dishes[j-1][i-1]+dishes[j+1][i-1]];
      }
   }
}

void printLine(int i)
{
   for(int j=0;j<DISHES;j++)
   {
      if(dishes[j][i]==0) printf(" ");
      else if(dishes[j][i]==1) printf(".");
      else if(dishes[j][i]==2) printf("x");
      else if(dishes[j][i]==3) printf("W");
   }
}

int main()
{
   //freopen("input.txt","r+",stdin);
   //freopen("output.txt","w+",stdout);
   int cases;
   scanf("%d ",&cases);
   for(int i=0;i<cases;i++)
   {
      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]);
      generate();
      for(int j=0;j<LINES;j++)
      {
         printLine(j);
         if(j<LINES-1) printf("\n");
      }
      if(i<cases-1) printf("\n\n");
   }
   return 0;
}

_________________________________________________________________
I'm not a driver with drinking problem.
I'm an alcoholic with driving problem.

[You must be registered and logged in to see this link.] | [You must be registered and logged in to see this link.]
avatar
BIT0130-Shakkhor
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 209
Points : 328

View user profile

Back to top Go down

CPP Re: Help wanted: 457 - Linear Cellular Automata

Post by BIT0102-Mohaimin on Wed Jun 08, 2011 2:17 am

Here are last few lines your program generates with the sample input.

Code:
WWWWWxWxxxxWxxxxWxx. . WxxWWWW WW  WWWWx
W  WWxxWWxxxWWxxxW x..WxxW  WWWW  W  WW
    WWxxWWxWxWWxWxWW .WWxxW  W  W    WWmohaimin@mohaimin:~/Desktop$

It should be:
Code:
WWWWWxWxxxxWxxxxWxx. . WxxWWWW WW  WWWWx
W  WWxxWWxxxWWxxxW x..WxxW  WWWW  W  WW
    WWxxWWxWxWWxWxWW .WWxxW  W  W    WW
mohaimin@mohaimin:~/Desktop$

The cursor should go at least the next line after the last line is printed, for ALL UVa problems. Sometimes more new lines are required if specified in the output format.
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

CPP Re: Help wanted: 457 - Linear Cellular Automata

Post by BIT0130-Shakkhor on Wed Jun 08, 2011 2:32 am

For this problem, this is very unlikely. Checked the [You must be registered and logged in to see this link.] and they seem to agree Sad I've tested with their sample input and output and everything seems to be okay. Neutral

But, I'm gonna give it a try, because I've tried everything else. Surprised
Thanks and Rep++

UPDATE: Well, that actually helped. It was accepted. Very Happy Thanks man.


Last edited by BIT0130-Shakkhor on Wed Jun 08, 2011 2:36 am; edited 1 time in total (Reason for editing : added update)

_________________________________________________________________
I'm not a driver with drinking problem.
I'm an alcoholic with driving problem.

[You must be registered and logged in to see this link.] | [You must be registered and logged in to see this link.]
avatar
BIT0130-Shakkhor
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 209
Points : 328

View user profile

Back to top Go down

CPP Re: Help wanted: 457 - Linear Cellular Automata

Post by BIT0102-Mohaimin on Wed Jun 08, 2011 2:44 am

Smile
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

CPP Re: Help wanted: 457 - Linear Cellular Automata

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum