10812 - Beat the Spread!
Moderator: Board moderators
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 10812 - Beat the Spread!
no need to reply.
i got AC.
i got AC.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Beat the spread -getting WA
can any1 help me with what is wrong about my code.here is my code-
#include<stdio.h>
int main()
{
int i,x,s,d,sum,min;
while(scanf("%d",&x)==1)
{
for(i=0;i<x;i++)
{
scanf("%d",&s);
scanf("%d",&d);
sum=(s+d);
min=(s-d);
if(s>d || s==d ) {
if((sum%2==0) && (min%2==0))
{
printf("%d\n",(s+d)/2);
printf("%d\n",(s-d)/2);
}
else printf("impossible\n");
}
else if(s<d) printf("impossible\n");}
}
return 0;
}
#include<stdio.h>
int main()
{
int i,x,s,d,sum,min;
while(scanf("%d",&x)==1)
{
for(i=0;i<x;i++)
{
scanf("%d",&s);
scanf("%d",&d);
sum=(s+d);
min=(s-d);
if(s>d || s==d ) {
if((sum%2==0) && (min%2==0))
{
printf("%d\n",(s+d)/2);
printf("%d\n",(s-d)/2);
}
else printf("impossible\n");
}
else if(s<d) printf("impossible\n");}
}
return 0;
}
10812-Beat the Spread
can any1 help me please ,with what is wrong about my code.here is my code-
#include<stdio.h>
int main()
{
int i,x,s,d,sum,min;
while(scanf("%d",&x)==1)
{
for(i=0;i<x;i++)
{
scanf("%d",&s);
scanf("%d",&d);
sum=(s+d);
min=(s-d);
if(s>d || s==d ) {
if((sum%2==0) && (min%2==0))
{
printf("%d\n",(s+d)/2);
printf("%d\n",(s-d)/2);
}
else printf("impossible\n");
}
else if(s<d) printf("impossible\n");}
}
return 0;
}
please its urgent
#include<stdio.h>
int main()
{
int i,x,s,d,sum,min;
while(scanf("%d",&x)==1)
{
for(i=0;i<x;i++)
{
scanf("%d",&s);
scanf("%d",&d);
sum=(s+d);
min=(s-d);
if(s>d || s==d ) {
if((sum%2==0) && (min%2==0))
{
printf("%d\n",(s+d)/2);
printf("%d\n",(s-d)/2);
}
else printf("impossible\n");
}
else if(s<d) printf("impossible\n");}
}
return 0;
}
please its urgent
Re: 10812 - Beat the Spread!
i need help.i just cant understand!!!!!
#include<stdio.h>
long x,y,s,d,n,i,a,b;
void BEAT_SPREAD()
{
scanf("%ld%ld",&s,&d);
if(s>=d)
{
x=(s+d);
y=(s-d);
a=x/2;
b=y/2;
if((x%2==0) && (y%2==0) && (a>0) && (b>0))
printf("%ld %ld",a,b);
else
printf("impossible");
}
else
printf("impossible");
printf("\n");
a=b=x=y=0;
}
int main(void)
{
while(scanf("%ld",&n)==1)
{
for( i = 1 ; i <= n ; i ++)
{
BEAT_SPREAD();
}
}
return 0;
}
#include<stdio.h>
long x,y,s,d,n,i,a,b;
void BEAT_SPREAD()
{
scanf("%ld%ld",&s,&d);
if(s>=d)
{
x=(s+d);
y=(s-d);
a=x/2;
b=y/2;
if((x%2==0) && (y%2==0) && (a>0) && (b>0))
printf("%ld %ld",a,b);
else
printf("impossible");
}
else
printf("impossible");
printf("\n");
a=b=x=y=0;
}
int main(void)
{
while(scanf("%ld",&n)==1)
{
for( i = 1 ; i <= n ; i ++)
{
BEAT_SPREAD();
}
}
return 0;
}
Re: 10812 - Beat the Spread!
I got it!!!!! i think more about this easy problem. The addition of two number is always even.so why should i check it?
Re: Beat the spread -getting WA
You're printing the two numbers on separate lines. They should be on the same line. See the problem's output sample. I don't think there is any other fault.
-
- New poster
- Posts: 19
- Joined: Thu May 20, 2010 8:58 am
Re: 10812 - Beat the Spread!
can any one say why um getting WA ?
thanking in advance
Code: Select all
#include<stdio.h>
int main(){
long a,b,tst;
scanf("%d",&tst);
while(tst--){
int s,d;
scanf("%d %d",&a,&b);
s=a+b;d=a-b;
if((a+b)%2)printf("impossible\n");
else if((a-b)%2)printf("impossible\n");
else if(a<b)printf("impossible\n");
else printf("%d %d\n",s/2,d/2);
}
return 0;
}
one day...
Re: 10812 - Beat the Spread!
#include<stdio.h>
int main()
{
long int t, s, d, a, c;
scanf("%d",&t);
while(t--)
{
scanf("%d %d", &s, &d);
a = (s - d) / 2;
if((s%2==0 && d%2!=0) || (s%2!=0 && d%2==0) || (s-d)<0) printf("impossible\n");
else
{ if(a < s-a){ c = a; a = s - a; }
printf("%d %d\n", a, c);
}
}
return 0;
}
This is my code I got WA . Please anybody help me.
int main()
{
long int t, s, d, a, c;
scanf("%d",&t);
while(t--)
{
scanf("%d %d", &s, &d);
a = (s - d) / 2;
if((s%2==0 && d%2!=0) || (s%2!=0 && d%2==0) || (s-d)<0) printf("impossible\n");
else
{ if(a < s-a){ c = a; a = s - a; }
printf("%d %d\n", a, c);
}
}
return 0;
}
This is my code I got WA . Please anybody help me.
Re: 10812 - Beat the Spread!
i m getting w.a..... here is my code
#include<stdio.h>
//#include<iostream.h>
int main()
{
int t,s,d,i,j;
scanf("%d",&t);
while(t>0)
{
scanf("%d%d",&s,&d);
if(s<d)
{
printf("impossible\n");
goto m;
}
for(i=d;i<=s;i++)
{
for(j=0;j<=d;j++)
{
if(i+j==s && i-j==d)
{
goto l;
}
}
}
printf("impossible\n");
goto m;
l: printf("%d %d\n",i,j);
m: t--;
}
// system("pause");
return 0;
}
Code: Select all
//#include<iostream.h>
int main()
{
int t,s,d,i,j;
scanf("%d",&t);
while(t>0)
{
scanf("%d%d",&s,&d);
if(s<d)
{
printf("impossible\n");
goto m;
}
for(i=d;i<=s;i++)
{
for(j=0;j<=d;j++)
{
if(i+j==s && i-j==d)
{
goto l;
}
}
}
printf("impossible\n");
goto m;
l: printf("%d %d\n",i,j);
m: t--;
}
// system("pause");
return 0;
}
-
- New poster
- Posts: 21
- Joined: Mon Jun 18, 2012 12:52 am
- Location: Dhaka, Bangladesh.
- Contact:
Re: 10812 - Beat the Spread!
Much easy problem. This samples might help.
Input:
Output:
Input:
Code: Select all
12
15 10
88 9
155 22
20 10
40 12
75 25
13 7
888 222
9999 1111
12365 123
99 11
13 19
Code: Select all
impossible
impossible
impossible
15 5
26 14
50 25
10 3
555 333
5555 4444
6244 6121
55 44
impossible
-
- New poster
- Posts: 4
- Joined: Fri Jul 27, 2012 1:53 pm
Re: 10812 - Beat the Spread!
Can Anyone help me finding problem at this code? I got wrong answer every time . Help me please
#include <stdio.h>
int main()
{
long int n, s, d, difference, big, small;
int i, count=0;
scanf("%ld", &n);
for(i=0; i<n; ++i)
{
scanf("%ld %ld", &s, &d);
if(d>s)
{
printf("impossible");
}
else if(d==0 && s%2==0)
{
printf("%ld %ld\n", s/2, s/2);
}
else if(s%2==0 && d%2==1)
printf("impossible\n");
else if(d==0 && s%2==1)
printf("impossible\n");
else
{
difference=s-d;
if(difference%2==1)
{
printf("impossible\n");
continue;
}
big = difference/2 + d;
small = s - big;
printf("%ld %ld\n", big, small);
}
}
return 0;
}
#include <stdio.h>
int main()
{
long int n, s, d, difference, big, small;
int i, count=0;
scanf("%ld", &n);
for(i=0; i<n; ++i)
{
scanf("%ld %ld", &s, &d);
if(d>s)
{
printf("impossible");
}
else if(d==0 && s%2==0)
{
printf("%ld %ld\n", s/2, s/2);
}
else if(s%2==0 && d%2==1)
printf("impossible\n");
else if(d==0 && s%2==1)
printf("impossible\n");
else
{
difference=s-d;
if(difference%2==1)
{
printf("impossible\n");
continue;
}
big = difference/2 + d;
small = s - big;
printf("%ld %ld\n", big, small);
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10812 - Beat the Spread!
line 16 is missing a newline.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 4
- Joined: Fri Jul 27, 2012 1:53 pm
Re: 10812 - Beat the Spread!
Thanks Bro.








-
- New poster
- Posts: 3
- Joined: Mon Jul 01, 2013 12:42 pm
Re: 10812 - Beat the Spread!
#include<stdio.h>
int main()
{
int i,sum,t,a,b,dif;
scanf("%d",&t);
for(i=1;i<=t;i++){
scanf("%d %d",&sum,&dif);
if(dif<=0 ||(dif+sum)%2==1 || sum<=0 || dif>sum)
printf("impossible\n");
else {
a=(dif+sum)/2;
b=sum-a;
if(a>=0 && b>=0){
if(a>b)
printf("%d %d\n",a,b);
else{printf("%d %d\n",b,a);}}
}
}
return 0;
}
I don't understand why I'm getting WA.Please help .
int main()
{
int i,sum,t,a,b,dif;
scanf("%d",&t);
for(i=1;i<=t;i++){
scanf("%d %d",&sum,&dif);
if(dif<=0 ||(dif+sum)%2==1 || sum<=0 || dif>sum)
printf("impossible\n");
else {
a=(dif+sum)/2;
b=sum-a;
if(a>=0 && b>=0){
if(a>b)
printf("%d %d\n",a,b);
else{printf("%d %d\n",b,a);}}
}
}
return 0;
}
I don't understand why I'm getting WA.Please help .
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10812 - Beat the Spread!
Input:Output should be:
Code: Select all
1
0 0
Code: Select all
0 0
Check input and AC output for thousands of problems on uDebug!