10257 - Dick and Jane

All about problems in Volume 102. 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
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

10257 - Dick and Jane

Post by htl »

Sorry for asking the silly problem... But I can't still figure out the answer.
Let S,P,Y as Spot,Puff and Yertle's age.

S=s+P
P=p+Y
S=y+Y
->S-P=s
P-Y=p
S-Y=y
->S-Y=p+s
->y=p+s

I only get the equation y=p+s,so I think the data problem gives is wrong:

in
5 5 10 9
5 5 10 10
5 5 11 10 ->maybe it's wrong

out
12 7 2
13 7 2
13 7 2

So I think the answer is not a constant. Could someone tell me where I'm wrong?
gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac »

Your mistake is in modelling the problem as a set of equations. It is a set of inequations. "My sister was 2 when I was born. Her
48th birthday is today. I am 45. How can this be?"
Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen »

my soln got W.A.
plz give me some inputs/outputs to find the bug.

thank u.
gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac »

razibcse
New poster
Posts: 50
Joined: Mon Jul 22, 2002 3:17 am
Location: SUST,BANGLADESH
Contact:

10257

Post by razibcse »

I thought it would b very easy..but always WA..can somebody tell me what's wrong with my output?

Code: Select all

#include <stdio.h>

void main()
{
long s,p,y,j,x,z,t,pp,ss;
while(scanf("%ld %ld %ld %ld",&s,&p,&y,&j)==4)
{
z=12+j-p-y;
x=z/3;
pp=x+p;
t=x+pp;
ss=(12+j)-t;
printf("%ld %ld %ld\n",ss,pp,x);
}
}
Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

Post by Caesum »

It seems to me that you are treating everything as integers. For example, suppose S is 1 when P is born, that means S could be 1.00 or could be 1.99. The effect of this is that the equations are not so simple to solve. To try and explain better:
You can form some equations from the conditions like:
S-P=s
P-Y=p
S-Y=y
It doesnt follow that s-p=y by adding the first two and equating with the second, because ages have been truncated to ints.
eg.
Spot was 2 when Puff was born. S-P=2
Puff was 1 when Yertle was born. P-Y=1
Spot was ? when Yertle was born. S-Y=?
So Spot must have been 3 when Yertle was born by your logic, but maybe Spot was nearly 3 when Puff was born and Puff was nearly 2 when Yertle was born, which woulc mean that Spot was nearly 5, or actually 4 when Yertle was born, and not 3.......
User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

What's wrong with mine

Post by yahoo »

I have read the topic of caesum and checked it with my code posted here. But it gives me wrong answer. Can anybody give me some test cases or kindly check my code and tell where i am wrong. Thanks in advance.

Code: Select all

#include<stdio.h>
#include<math.h>
main()
{
	long long int i,j,k,sp,yr,pf,z,x,y,c,s,p,s1,p1,y1,z1;
	while(scanf("%lld%lld%lld%lld",&s,&p,&y,&z)!=EOF)
	{
		sp=(12+z+s+y)/3;
		pf=sp-s;
		yr=sp-y;
		s1=s+1;
		p1=p+1;
		y1=y+1;
		for(i=sp-5;i<sp+5;i++)
			if(i>0 && i<(12+z))
				for(j=pf-5;j<pf+5;j++)
					if(j>0 && j<(12+z))
						for(k=yr-5;k<yr+5;k++)
						{
							if(k>0 && k<(12+z))
							{
								c=0;
								if(((i-j)==s)||((i-j)==s1)) c++;
								if(((j-k)==p)||((j-k)==p1)) c++;
								if(((i-k)==y)||((i-k)==y1)) c++;
								if((i+j+k)==(12+z)) c++;
								if(c==4) x=i,y=j,z=k,i=sp+10,j=pf+10,k=yr+10;
							}
						}
		printf("%lld %lld %lld\n",x,y,z);
	}
	return 0;
}
[c][/c] :oops:
InOutMoTo
New poster
Posts: 18
Joined: Sun Aug 10, 2003 12:47 pm

Post by InOutMoTo »

Thx. According this test data~ I found my mistake and got AC :lol:

Only need to worry when s+p != y , Puff should +1 age before Spot.
(Using trial & error , I finally found that :oops: )
daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon »

Hi,

Test cases can be found at Waterloo's site:
http://plg.uwaterloo.ca/~acm00/

This question can be easily solved by brute force.
stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Re: 10257 - Dick and Jane

Post by stcheung »

In case you still got stuck, here's some more hint.
First calculate S,P,Y as int. Check if this triplet satisifies all conditions. If not, try adding 1 to one or more of these and see which combination can satisfy all conditions. Very straightforward and brute-force but no need for using doubles.
roland414
New poster
Posts: 1
Joined: Thu Feb 17, 2011 1:07 pm

Re: 10257 - Dick and Jane

Post by roland414 »

Thank you for posting this.
testinguser
New poster
Posts: 1
Joined: Fri Jul 27, 2012 6:13 am

Re: 10257 - Dick and Jane

Post by testinguser »

I still don't get it..
I know that when S+P != Y, then one of them must have its age increased by 1...
but whom should we add this increment to ?

For example :
5 5 11 10
should yield : 13 7 2

Yertle = 2;
Puff = Yertle + p => 2 + 5 => 7;

Spot = Puff + s => 7 + 5 => 12 OR
Spot = Yertle + y => 2 + 11 => 13. --> We must choose this one since (13 + 7 + 2) == 12 + 10.

From this analysis, it seems that we only need to increase Spot's age. Yertle and Puff doesn't need to be changed.
Is my assumption correct ?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10257 - Dick and Jane

Post by brianfry713 »

In my AC code I first calculate the minimum age of Spot, Puff, and Yertle. Then I try all 2*2*2=6 combinations of that minimum age and plus one for each of them. Each combination is checked against the 4 conditions until the answer is found.
Check input and AC output for thousands of problems on uDebug!
hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

Re: 10257 - Dick and Jane

Post by hello »

I really do not see any brute force application. Problem is that Age can be Advance in +1 for both Spot & Puff (As described in the first paragraph of the description).
So You can easily decide that when you are calculating Yertle's age, by extra calculation of taking mod 3. The only complex part is when age is advance in only +1 then Spot or Puff anyone's age can be advance in +1. If you cleaver enough you can explore it by debugging in as the TEST cases hold the answer of this confusion. Oh You may be also prove it by math. If you can then post it :). I think the problem just need flagging (from mod 3).
metaphysis
Experienced poster
Posts: 139
Joined: Wed May 18, 2011 3:04 pm

Re: 10257 - Dick and Jane

Post by metaphysis »

For test data:

Code: Select all

1 2 5 3
uDebug gives the answer:

Code: Select all

8 5 2
How it can be? If age difference of Spot and Puff is 1 or 2, I can understand easily, but the difference is 3, anyone can explain me? Thanks!
Post Reply

Return to “Volume 102 (10200-10299)”