434 - Matty's Blocks
Moderator: Board moderators
-
- New poster
- Posts: 18
- Joined: Thu Jun 20, 2002 4:54 pm
434 - Matty's Blocks
This is stupidly simple problem, yet I have not been accepted. There seems to be a large ratio of wa/ac, so I don't think I am the only one to have this problem. Is there any quirks to this problem? My solution is Min = Max( sum(Front), sum(Right) ), Max = sum( Min( Front, Right ) ), Extra = Max - Min.
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
-
- New poster
- Posts: 18
- Joined: Thu Jun 20, 2002 4:54 pm
Why I get WA in 434
This is my code, if anybody know what is wrong pleas tell me.
var
temp,prawo:array[0..8] of byte;
przod:array[0..8,1..3] of byte;
s,m,t,n,k,j,i:byte;
f:text;
begin
assign(f,'dane.txt');
reset(f);
readln(f,n);
for j:=1 to n do
begin
for i:=0 to 8 do
begin
przod[i,1]:=0;
przod[i,2]:=0;
przod[i,3]:=0;
prawo:=0;
end;
readln(f,k);
for i:=1 to k do
begin
read(f,t);
inc(przod[t,1]);
end;
readln(f);
for i:=1 to k do
begin
read(f,t);
inc(prawo[t]);
temp:=t;
end;
s:=0;
for i:=1 to 8 do
if prawo>przod[i,1] then
s:=s+i*prawo
else
s:=s+i*przod[i,1];
przod[1,2]:=przod[1,1];
for i:=2 to 8 do
przod[i,2]:=przod[i,1]*i+przod[i-1,2];
przod[8,3]:=0;
for i:=7 downto 1 do
przod[i,3]:=przod[i+1,3]+przod[i+1,1];
m:=0;
for i:=1 to k do
m:=m+przod[temp,2]+temp*przod[temp,3];
writeln('Matty needs at least ',s,' blocks, and can add at most ',m-s,' extra blocks.');
end;
close(f);
readln;
end.
var
temp,prawo:array[0..8] of byte;
przod:array[0..8,1..3] of byte;
s,m,t,n,k,j,i:byte;
f:text;
begin
assign(f,'dane.txt');
reset(f);
readln(f,n);
for j:=1 to n do
begin
for i:=0 to 8 do
begin
przod[i,1]:=0;
przod[i,2]:=0;
przod[i,3]:=0;
prawo:=0;
end;
readln(f,k);
for i:=1 to k do
begin
read(f,t);
inc(przod[t,1]);
end;
readln(f);
for i:=1 to k do
begin
read(f,t);
inc(prawo[t]);
temp:=t;
end;
s:=0;
for i:=1 to 8 do
if prawo>przod[i,1] then
s:=s+i*prawo
else
s:=s+i*przod[i,1];
przod[1,2]:=przod[1,1];
for i:=2 to 8 do
przod[i,2]:=przod[i,1]*i+przod[i-1,2];
przod[8,3]:=0;
for i:=7 downto 1 do
przod[i,3]:=przod[i+1,3]+przod[i+1,1];
m:=0;
for i:=1 to k do
m:=m+przod[temp,2]+temp*przod[temp,3];
writeln('Matty needs at least ',s,' blocks, and can add at most ',m-s,' extra blocks.');
end;
close(f);
readln;
end.
NOthing special
Re: Why I get WA in 434
Why do you use byte? change them with integer.qndel wrote:var
temp,prawo:array[0..8] of byte;
przod:array[0..8,1..3] of byte;
s,m,t,n,k,j,i:byte;
434 - Matty's Blocks
Can anyone send me some test cases on this problem...
I cant find why I m getting WA.
Thans.
I cant find why I m getting WA.
![:-?](./images/smilies/icon_confused.gif)
Thans.
Last edited by Jan on Tue Jul 26, 2005 6:47 pm, edited 1 time in total.
Ami ekhono shopno dekhi...
HomePage
HomePage
Can anyone kindly post their output fot this input
Code: Select all
10
6
4 5 3 3 0 0
5 3 4 2 3 4
7
6 0 2 5 4 0 6
0 6 5 6 3 5 3
3
0 2 0
2 0 1
7
3 0 2 3 5 8 1
8 1 4 1 1 0 6
7
5 6 4 3 0 0 2
5 4 1 3 0 1 6
5
3 3 2 3 3
2 0 3 1 1
6
3 0 5 1 4 2
5 1 4 4 2 1
8
2 0 5 7 1 6 6 0
6 6 0 5 7 4 4 1
1
0
0
2
8 0
4 8
My Accepted code returns...
Output:
Hope it works.
Output:
Code: Select all
Matty needs at least 21 blocks, and can add at most 54 extra blocks.
Matty needs at least 34 blocks, and can add at most 82 extra blocks.
Matty needs at least 3 blocks, and can add at most 0 extra blocks.
Matty needs at least 34 blocks, and can add at most 43 extra blocks.
Matty needs at least 22 blocks, and can add at most 58 extra blocks.
Matty needs at least 16 blocks, and can add at most 18 extra blocks.
Matty needs at least 20 blocks, and can add at most 42 extra blocks.
Matty needs at least 35 blocks, and can add at most 111 extra blocks.
Matty needs at least 0 blocks, and can add at most 0 extra blocks.
Matty needs at least 12 blocks, and can add at most 0 extra blocks.
Ami ekhono shopno dekhi...
HomePage
HomePage
I spent quite some time on this problem, so just want to share my thoughts on this. Basically, finding the maximum isn't as hard as it may seem and finding the minimum may be slightly harder than you thought. For me, I actually got stuck for quite some time on finding the minimum. But after manually verifying why the following input would yield a minimum of 34, the solution was immediately obvious So for those of you who got stuck on the minimum like I did, I urge you to take the time to work out the answer on paper first.
7
3 0 2 3 5 8 1
8 1 4 1 1 0 6
7
3 0 2 3 5 8 1
8 1 4 1 1 0 6
Re: 434 - Matty's Blocks
I agree with stcheuung. This problem is so simple.
-
- Experienced poster
- Posts: 139
- Joined: Wed May 18, 2011 3:04 pm
Re: 434 - Matty's Blocks
For minimum blocks, make sure the blocks viewed from front and right are same, and make the cross point shared by front view and right view.
For example:
7
3 0 2 3 5 8 1
8 1 4 1 1 0 6
8 pairs to 8, 1 pairs to 1, 0 pairs to 0
and remains have no pair, so they should be placed singlely, so total minimum blocks is
8 + 1 + 0 + (3 + 2 + 3 + 5) + (1 + 4 + 1 + 6) = 34
For example:
7
3 0 2 3 5 8 1
8 1 4 1 1 0 6
8 pairs to 8, 1 pairs to 1, 0 pairs to 0
and remains have no pair, so they should be placed singlely, so total minimum blocks is
8 + 1 + 0 + (3 + 2 + 3 + 5) + (1 + 4 + 1 + 6) = 34
metaphysis: http://uhunt.onlinejudge.org/id/95895
My solutions for UVa problems: https://github.com/metaphysis/Code.
My solutions for UVa problems: https://github.com/metaphysis/Code.