Page 1 of 1

11040 - Add bricks in the wall

Posted: Sat Jul 08, 2006 11:05 am
by sunnycare
who can check my code?
i dont know why?
i use gcc compile it on my computer ,and it works well...

Code: Select all

#include <stdio.h>

int main()
{
	int wall[9][9];
	int cases;
	scanf("%d",&cases);
	int row,col;
	while(cases-->0)
	{
		for(row=0;row<=8;row+=2)
		{
			for(col=0;col<=row;col+=2)
			{
				scanf("%d",&(wall[row][col]));
			}
		}
		for(row=0;row<=6;row+=2)
		{
			for(col=0;col<=row;col+=2)
			{
				wall[row+2][col+1]=(wall[row][col]-wall[row+2][col]-wall[row+2][col+2])/2;
				wall[row+1][col]=wall[row+2][col]+wall[row+2][col+1];
				wall[row+1][col+1]=wall[row+2][col+2]+wall[row+2][col+1];
			}
		}
		for(row=0;row<=8;row++)
		{
			for(col=0;col<=row;col++)
			{
				printf("%d ",wall[row][col]);
			}
			printf("\n");
		}
	}
	return 0;
}

Posted: Sat Jul 08, 2006 12:25 pm
by Moha
If you want to compile your code as a c code you will have some problems. because you should move up your col, row before the scanf statement.

Posted: Sat Jul 08, 2006 12:26 pm
by ayon
did you submit this for judging with C ? you declared some variables below scanf(), C will give you CE, but C++ wont

3x

Posted: Mon Jul 10, 2006 6:14 am
by sunnycare
thanks..

i agree ...

Posted: Wed Jul 12, 2006 12:27 pm
by Rocky
yes ayon is right i agree with him...

thank's....
Rocky

11040 - Add bricks in the wall

Posted: Wed Aug 23, 2006 1:14 am
by unaben
I am getting WA with my code :( Can someone plz give me a hint.

Here is the code:

#include<iostream>

using namespace std;

void handle()
{
int array[49];
cin>>array[0]>>array[3]>>array[5]>>array[10]>>array[12]>>array[14]>>array[21]>>array[23]>>array[25]>>array[27]
>>array[36]>>array[38]>>array[40]>>array[42]>>array[44];
array[1]=array[3]+array[5];
array[4]=array[1]-array[3];
array[2]=array[4]+array[5];
array[6]=array[10]+array[14];
array[7]=array[3]-array[6];
array[8]=array[4]-array[7];
array[9]=array[5]-array[8];
array[11]=array[6]-array[10];
array[12]=array[7]-array[11];
array[13]=array[8]-array[12];
array[15]= array[21]+ array[27];
array[16]= array[10]-array[15];
array[17]=array[11]-array[16];
array[18]=array[12]-array[17];
array[19]=array[13]-array[18];
array[20]=array[14]-array[19];
array[22]=array[15]- array[21];
array[24]=array[17]-array[23];
array[26]=array[19]- array[25];
array[28]=array[42]+ array[44];
array[29]=array[21]-array[28];
array[30]=array[22]-array[29];
array[31]=array[23]-array[30];
array[32]=array[24]-array[31];
array[33]=array[25]-array[32];
array[34]=array[26]-array[33];
array[35]=array[27]-array[34];
array[37]=array[28]-array[36];
array[39]=array[30]-array[38];
array[40]=array[31]-array[39];
array[41]=array[32]-array[40];
array[43]=array[35]-array[44];

int counter=0;
for(int i=0; i<=44; i++)
{
cout<<array<<" ";
if(counter==0 or counter==2 or counter==5 or counter==9 or
counter==14 or counter==20 or counter==27 or counter==35)
cout<<endl;
counter++;
}
cout<<endl;
}

int main()
{
int n;
cin>>n;
for(int i=0; i<n; i++)
handle();
}

Thanx in advance :wink:

Posted: Wed Aug 23, 2006 3:05 am
by Erik
Hi,

Try the following case:

Code: Select all

128
32 32
8 8 8
2 2 2 2
0 0 0 0 0
Cu, Erik :D

Posted: Wed Aug 23, 2006 2:11 pm
by unaben
I see! However, I am not sure how to find the value of the first brick from the eight row. :oops:

Thanx Erik :wink:

Posted: Wed Aug 23, 2006 9:56 pm
by Martin Macko
unaben wrote:I see! However, I am not sure how to find the value of the first brick from the eight row. :oops:

Thanx Erik :wink:
Assume you have the following six bricks:

Code: Select all

  A
 x y
B z C
and you know the values of A, B and C. By the rule
problem statement wrote:the number of a brick is obtained by adding the numbers of the two bricks below it.
you get an equation system of three equations with three unknowns:

Code: Select all

A=x+y
x=B+z
y=C+z
By solving the system you get what you need.

Posted: Thu Aug 24, 2006 8:58 pm
by unaben
Thanx Macko! I got AC :D It seems that my previous code had no logic at all :oops: