Hello...besides the sample input being wrong, is there something else
tricky with this question? Somebody in the ranklist said to use pascal
if it doesn't work, but people did solve it using c++.
I'll post my code since it's so short (in case I did something really
dumb), but I'll only keep it up till somebody helps me.
Last edited by broderic on Tue Jul 30, 2002 2:52 am, edited 1 time in total.
With your code you don't consider the case, that the mobile is in equilibrium in the highest level, but not in equilibrium in a lower level. Use a flag to indicate if anywhere was a level where the mobile wasn't in equilibrium.
The problem, which made people like me use Pascal instead of C/C++, is already fixed.
Read the complete input, even if you know there is an error at an early stage. Your function mobile() returns if it encounters an error in the left branch and leaves the right branch unread.
I still don't understand why I have to read the complete input.
If I got error in reading left branch, do I have to read the
right branch? Is it necessary?
I still don't understand why I have to read the complete input.
If I got error in reading left branch, do I have to read the
right branch? Is it necessary?
Well, don't forget that this problem has multiple input, ie, more than one mobile may be present in the input. Therefore, it is necessary to read a single mobile completely in order to correctly read the start of the next mobile....
"Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic."
Can anyone tell me, why is the following case should give "No"?
1
0 2 0 2
1 3 1 1
1 1 1 3
From the problem specification, I can't find a clear statement stating that all the sub-mobiles are also required to be in equilibrium.......
But it seems that "checking equilibrium of sub-mobile" is the key to accepted.........
My signature:
Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code.
Equilibrium in this problem is defined as a condition where the product of the left distance with the TOTAL left mobile weight (although there may be a sub mobile in the left mobile not equilibrium) equals to that of the right.
Example:
Input =
0 12 96 1
1 2 3 2
2 4 2 4
Left - mobile : 0 left distance : 12
sub 1 : 1 2 3 2 (not equilibrium)
sub 2 : 2 4 2 4 (equilibrium)
Total weight of left - mobile is 8
Right - mobile : 96 right distance : 1
so the math : left weight * left distance = 12 * 8 = 96
right weight * right distance = 96 * 1 = 96
So this system, according to me is equilibrium. Is this correct?
If false, what's the right definition of 'equilibrium' ?
i got wa with the code following...
can anyone help me to check it/
[pascal]
var
kase : integer;
equ : boolean;
function balance : double;
var w1, d1, w2, d2 : longint;
l, r : double;
begin
readln(w1, d1, w2, d2);
if not equ then exit;
if w1 > 0 then l := w1 else l := balance;
if w2 > 0 then r := w2 else r := balance;
if abs(l * d1 - r * d2) > 1e-7 then begin equ := false; exit; end;
balance := r * (d1 + d2) / d1;
end;
begin
readln(kase);
while kase > 0 do
begin
equ := true;
balance;
if equ then
writeln('YES')
else
writeln('NO');
dec(kase);
if kase > 0 then writeln;
end;
end.
[/pascal]
void pushStack(MOB* pushed){
if(stackLast==NULL){
//stackStart=pushed;
stackLast=pushed;
pushed->stack=NULL;
}
else{
if(stackLast->leftWeight==0 && stackLast->l_Mob==NULL){
stackLast->l_Mob=pushed;
// all mobile hanged.
if(stackLast->rightWeight!=0 || stackLast->r_Mob!=NULL){
// new mobile should be pushed
if(pushed->leftWeight==0 || pushed->rightWeight==0){
pushed->stack=stackLast->stack;
stackLast=pushed;
}
// don't have to
else{
stackLast=stackLast->stack;
}
}
// wait right sub mobile.
else{
// & push current
if(pushed->leftWeight==0 || pushed->rightWeight==0){
pushed->stack=stackLast;
stackLast=pushed;
}
}
}
else if(stackLast->rightWeight==0 && stackLast->r_Mob==NULL){
stackLast->r_Mob=pushed;
// all mobile hanged.
// new mobile should be pushed
if(pushed->leftWeight==0 || pushed->rightWeight==0){
pushed->stack=stackLast->stack;
stackLast=pushed;
}
// don't have to
else{
stackLast=stackLast->stack;
}
}
}
}