10257 - Dick and Jane
Moderator: Board moderators
10257 - Dick and Jane
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?
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?
http://plg.uwaterloo.ca/~acm00/S98-1/test_data/ (problem B)
10257
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);
}
}
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.......
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.......
What's wrong with mine
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.
[c][/c] ![:oops:](./images/smilies/icon_redface.gif)
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;
}
![:oops:](./images/smilies/icon_redface.gif)
Thx. According this test data~ I found my mistake and got ACgvcormac wrote:http://plg.uwaterloo.ca/~acm00/S98-1/test_data/ (problem B)
![:lol:](./images/smilies/icon_lol.gif)
Only need to worry when s+p != y , Puff should +1 age before Spot.
(Using trial & error , I finally found that
![:oops:](./images/smilies/icon_redface.gif)
Hi,
Test cases can be found at Waterloo's site:
http://plg.uwaterloo.ca/~acm00/
This question can be easily solved by brute force.
Test cases can be found at Waterloo's site:
http://plg.uwaterloo.ca/~acm00/
This question can be easily solved by brute force.
Re: 10257 - Dick and Jane
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.
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.
-
- New poster
- Posts: 1
- Joined: Fri Jul 27, 2012 6:13 am
Re: 10257 - Dick and Jane
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 ?
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 ?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10257 - Dick and Jane
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!
Re: 10257 - Dick and Jane
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).
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
![:)](./images/smilies/icon_smile.gif)
-
- Experienced poster
- Posts: 139
- Joined: Wed May 18, 2011 3:04 pm
Re: 10257 - Dick and Jane
For test data:
uDebug gives the answer:
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!
Code: Select all
1 2 5 3
Code: Select all
8 5 2
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.