10812  Beat the Spread!
Moderator: Board moderators
10812  Beat the Spread!
Hello all,
I'm having a bit of a trouble with problem 10812: Beat the Spread!
Although the problem seems more than easy: x+y = s, xy = d => ... => x = (s+d)/2 and y = (sd)/2, finally check if both x and y a are non negative.
The problem is that I keep getting WA and I cannot figure why. Any sugestions?
Thanks in advance.
./noddy
I'm having a bit of a trouble with problem 10812: Beat the Spread!
Although the problem seems more than easy: x+y = s, xy = d => ... => x = (s+d)/2 and y = (sd)/2, finally check if both x and y a are non negative.
The problem is that I keep getting WA and I cannot figure why. Any sugestions?
Thanks in advance.
./noddy
You should check whether all these conditions hold: s >= d, (s + d) even, (s  d) even. When either fails, the answer is "impossible."
Last edited by mf on Mon Mar 21, 2005 8:26 pm, edited 1 time in total.

 Learning poster
 Posts: 70
 Joined: Sat Feb 05, 2005 9:38 am
 Location: Gurukul
Re
Hi taborda,
Lets see an example :
x=15,y=12
then x+y=27 (odd)
and xy=3 (odd)
then if u do 27/2=13.5
and 3/2=1.5 all the result is fraction
now we see that there is no two integer(not fraction) which summation is X and difference is Y, thats why we check it for even. So for this input output should be "impossible". Hope it helps. Good Luck.
Lets see an example :
x=15,y=12
then x+y=27 (odd)
and xy=3 (odd)
then if u do 27/2=13.5
and 3/2=1.5 all the result is fraction
now we see that there is no two integer(not fraction) which summation is X and difference is Y, thats why we check it for even. So for this input output should be "impossible". Hope it helps. Good Luck.
Some Love Stories Live Forever ....

 New poster
 Posts: 2
 Joined: Sat Jun 04, 2005 10:07 pm
10812 So easy... =(
This problem is giving me some WA's and I dont know how to solve this. This problem is very easy, I know, but my code is wrong somewhere. I'll leave the code I'm using, here. I hope someone can give me an hint. This problem doesn't deserve so much time. Thanks...
Code: Select all
#include "stdio.h"
int main()
{
unsigned long int num, i, first, sec, x, y;
scanf("%lu", &num);
for(i=0; i<num;i++)
{
scanf("%lu", &first);
scanf("%lu", &sec);
x=(first+sec)/2;
y=(firstsec)/2;
if(first<=sec  (first+sec)%2  (firstsec)%2  x<0  y<0)
{
printf("impossible\n");
continue;
}
printf("%lu %lu\n", y, x);
}
return 0;
}

 Experienced poster
 Posts: 131
 Joined: Sat Jul 17, 2004 4:09 am
 Location: Lima, Per
Re: 10812 So easy... =(
Checking (first<=sec) discards possible solutions...gateKeeper wrote:Code: Select all
if(first<=sec  (first+sec)%2  (firstsec)%2  x<0  y<0) { printf("impossible\n"); continue; }
Ciao!!!
Claudio

 Experienced poster
 Posts: 209
 Joined: Sun Jan 16, 2005 6:22 pm
10812...WA??
Last edited by asif_rahman0 on Sun Jun 11, 2006 8:32 pm, edited 1 time in total.
 Martin Macko
 A great helper
 Posts: 481
 Joined: Sun Jun 19, 2005 1:18 am
 Location: European Union (Slovak Republic)
Re: 10812...WA??
There is already a topic on this problem. See http://onlinejudge.uva.es/board/viewtopic.php?t=7782. Never create a new topic on a problem if there is already one on that problem.asif_rahman0 wrote:where is the fault in my code??
plz help.
Anyway, your solution assumes something that's not written in the problem statement. What if s=d? Read the problem description more carefully.

 Experienced poster
 Posts: 209
 Joined: Sun Jan 16, 2005 6:22 pm

 New poster
 Posts: 13
 Joined: Sat Dec 02, 2006 7:51 am
 Location: Indonesia
 Contact:
I still don't get it. I've tried all possible corrections, but none get AC.
I suppose that both the sum & difference must be either even or odd. I still get WA.
e.g.:
1. 15 12 (Odd & Even)
x + y = 15
x  y = 12
 +
x = (15  12) / 2
(doesn't fulfil)
2. 14 11 (Even & Odd)
x + y = 14
x  y = 11
 +
x = (14  11) / 2
(doesn't fulfil)
3. 15 11 (Odd & Odd)
x + y = 15
x  y = 11
 +
x = (15  11) / 2
(fulfils)
4. 14 10 (Even & Even)
x + y = 14
x  y = 10
 +
x = (14  10) / 2
(fulfils)
Here's my code:
I suppose that both the sum & difference must be either even or odd. I still get WA.
e.g.:
1. 15 12 (Odd & Even)
x + y = 15
x  y = 12
 +
x = (15  12) / 2
(doesn't fulfil)
2. 14 11 (Even & Odd)
x + y = 14
x  y = 11
 +
x = (14  11) / 2
(doesn't fulfil)
3. 15 11 (Odd & Odd)
x + y = 15
x  y = 11
 +
x = (15  11) / 2
(fulfils)
4. 14 10 (Even & Even)
x + y = 14
x  y = 10
 +
x = (14  10) / 2
(fulfils)
Here's my code:
Code: Select all
#include<stdio.h>
void main()
{
int i, s, d, n, a, c;
while(scanf("%d", &n)==1)
{
for(i=0; i<n; i++)
{
scanf("%d %d", &s, &d);
a = (s  d) / 2;
if((s%2==0 && d%2!=0)  (s%2!=0 && d%2==0)  (sd)<0) printf("impossible\n");
else
{ if(a < sa){ c = a; a = s  a; }
printf("%d %d\n", a, c);
}
}
}
}
"The Only Thing For The Triumph of Evil is For a Good Man to Do Nothing"
Suppose the input is 20 0. Now according to your code...
The output should be 10 10. Hope it helps.
Code: Select all
scanf("%d %d", &s, &d); /* s = 20, d = 0 */
a = (s  d) / 2; /* So, a = 10 */
if((s%2==0 && d%2!=0)  (s%2!=0 && d%2==0)  (sd)<0)
printf("impossible\n"); /* s and d both are even and sd > 0 */
else
{ if(a < sa){ c = a; a = s  a; } /* a = 10, sa = 10, so a is not less than (sa) */
printf("%d %d\n", a, c); /* Now c is not initialized */
}
Ami ekhono shopno dekhi...
HomePage
HomePage

 New poster
 Posts: 13
 Joined: Sat Dec 02, 2006 7:51 am
 Location: Indonesia
 Contact:

 Experienced poster
 Posts: 136
 Joined: Sat Nov 29, 2008 8:01 am
 Location: narayangong,bangladesh.
 Contact:
Re: whats wrong?? Beat the Spread!
plz someone help me.
why wrong ans!!!
here my code.
why wrong ans!!!
here my code.
Code: Select all
#include<stdio.h>
int main()
{ int s1,s2;
int s,d;
int numinput,i;
scanf("%d",&numinput);
for(i=1;i<=numinput;i++)
{
scanf("%d %d",&s,&d);
if(d>=s){
printf("impossible\n");
}
else if
((s+d)%2!=0  (sd)%2!=0  (s+d)<0  (sd)<0)
printf("impossible\n");
else
{ s1=((s+d)/2);
s2=ss1;
printf("%d %d\n",s1,s2);
}
}
return 0;
}
Life is more complicated than algorithm.
http://felixhalim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felixhalim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com