11040 - Add bricks in the wall

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

Moderator: Board moderators

Post Reply
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

11040 - Add bricks in the wall

Post 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;
}
Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post 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.
ayon
Experienced poster
Posts: 161
Joined: Tue Oct 25, 2005 8:38 pm
Location: buet, dhaka, bangladesh

Post by ayon »

did you submit this for judging with C ? you declared some variables below scanf(), C will give you CE, but C++ wont
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program
sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

3x

Post by sunnycare »

thanks..
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

i agree ...

Post by Rocky »

yes ayon is right i agree with him...

thank's....
Rocky
unaben
New poster
Posts: 12
Joined: Mon Jul 10, 2006 10:47 pm

11040 - Add bricks in the wall

Post 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:
Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

Post 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
unaben
New poster
Posts: 12
Joined: Mon Jul 10, 2006 10:47 pm

Post 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:
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post 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.
unaben
New poster
Posts: 12
Joined: Mon Jul 10, 2006 10:47 pm

Post by unaben »

Thanx Macko! I got AC :D It seems that my previous code had no logic at all :oops:
Post Reply

Return to “Volume 110 (11000-11099)”