10812 - Beat the Spread!

All about problems in Volume CVIII. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Re: 10812 - Beat the Spread!

Postby sazzadcsedu » Fri Dec 26, 2008 11:24 pm

no need to reply.
i got AC.
sazzadcsedu
Experienced poster
 
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.

Beat the spread -getting WA

Postby nhrahi » Tue Aug 25, 2009 7:47 pm

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;
}
nhrahi
New poster
 
Posts: 6
Joined: Tue Aug 25, 2009 7:38 pm

10812-Beat the Spread

Postby nhrahi » Fri Sep 11, 2009 1:02 am

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
nhrahi
New poster
 
Posts: 6
Joined: Tue Aug 25, 2009 7:38 pm

Re: 10812 - Beat the Spread!

Postby sms.islam » Sat Oct 10, 2009 4:02 pm

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;
}
sms.islam
New poster
 
Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

Re: 10812 - Beat the Spread!

Postby sms.islam » Sun Oct 11, 2009 10:49 am

I got it!!!!! i think more about this easy problem. The addition of two number is always even.so why should i check it?
sms.islam
New poster
 
Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

Re: Beat the spread -getting WA

Postby gtcoder » Thu Dec 09, 2010 10:31 pm

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.
gtcoder
New poster
 
Posts: 12
Joined: Tue Mar 23, 2010 5:45 am

Re: 10812 - Beat the Spread!

Postby kissu parina » Fri Feb 04, 2011 6:13 pm

can any one say why um getting WA ?
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;
}

thanking in advance
one day...
kissu parina
New poster
 
Posts: 19
Joined: Thu May 20, 2010 8:58 am

Re: 10812 - Beat the Spread!

Postby rasel2707 » Tue Feb 15, 2011 6:55 pm

#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.
rasel2707
New poster
 
Posts: 1
Joined: Sat Feb 05, 2011 6:32 pm

Re: 10812 - Beat the Spread!

Postby shoaib7k » Fri Sep 09, 2011 3:50 pm

i m getting w.a..... here is my code[code][/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;
}
shoaib7k
New poster
 
Posts: 10
Joined: Thu Aug 18, 2011 7:45 pm

Re: 10812 - Beat the Spread!

Postby PromeNabid » Sat Jun 30, 2012 10:06 pm

Much easy problem. This samples might help.
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

Output:
Code: Select all
impossible
impossible
impossible
15 5
26 14
50 25
10 3
555 333
5555 4444
6244 6121
55 44
impossible
PromeNabid
New poster
 
Posts: 17
Joined: Mon Jun 18, 2012 12:52 am
Location: Dhaka, Bangladesh.

Re: 10812 - Beat the Spread!

Postby sulaimansust » Fri Jul 27, 2012 1:56 pm

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;
}
sulaimansust
New poster
 
Posts: 4
Joined: Fri Jul 27, 2012 1:53 pm

Re: 10812 - Beat the Spread!

Postby brianfry713 » Sat Jul 28, 2012 1:27 am

line 16 is missing a newline.
Check input and AC output for hundreds of problems on uDebug!
brianfry713
Guru
 
Posts: 5318
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10812 - Beat the Spread!

Postby sulaimansust » Sat Jul 28, 2012 2:29 am

Thanks Bro. :) :) :) :) :) :) :)
sulaimansust
New poster
 
Posts: 4
Joined: Fri Jul 27, 2012 1:53 pm

Re: 10812 - Beat the Spread!

Postby SifatRuet12 » Wed Jul 10, 2013 10:45 pm

#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 .
SifatRuet12
New poster
 
Posts: 3
Joined: Mon Jul 01, 2013 12:42 pm

Re: 10812 - Beat the Spread!

Postby brianfry713 » Thu Jul 11, 2013 11:36 pm

Input:
Code: Select all
1
0 0
Output should be:
Code: Select all
0 0
Check input and AC output for hundreds of problems on uDebug!
brianfry713
Guru
 
Posts: 5318
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

PreviousNext

Return to Volume CVIII

Who is online

Users browsing this forum: No registered users and 1 guest