#include<cstdio>

int main()

{

int a,b,x,y,i=1,t;

scanf(“%d”,&t);

while (i<=t)

{

scanf(“%d %d”,&a,&b);

if (a>=b&&(a+b)%2==0)

{

x=(a+b)/2;

y=(a-b)/2;

printf(“%d %d\n”,x,y);

}

else

printf(“impossible\n”);

i++;

}

return 0;

}

int main()

{

int a,b,x,y,i=1,t;

scanf(“%d”,&t);

while (i<=t)

{

scanf(“%d %d”,&a,&b);

if (a>=b&&(a+b)%2==0)

{

x=(a+b)/2;

y=(a-b)/2;

printf(“%d %d\n”,x,y);

}

else

printf(“impossible\n”);

i++;

}

return 0;

}

why (a+b)%2 ??

ReplyDeleteand why x=(a+b)/2;

y=(a-b)/2; ????

Because,

ReplyDeleteFirst input integer is the sum of final score.

That is x+y=a. .....(1)

Second input integer is the difference between two final score.

That is x-y=b. ......(2)

By (1)+(2),

x=(a+b)/2

And By (1)-(2)

y=(a-b)/2

That is why we do not get the absulate value if (a+b) is not divisable by 2.

i tried y=x-a; in stead of y=(a-b)/2; but uva shows verdict Wrong Answer but when i changed it from y=x-a to y=(a-b)/2 i was accepted...

ReplyDeletethough both are equal why it was not accpted...

reply please...

Think what r u doing and what actually need to do. I think u can find the solution by yours. Best of luck.

Deletewhat,s the problem here

ReplyDelete#include

int main()

{

int t,s,d,a,b,n;

scanf("%d",&n);

for(t=1;t<=n;t++){

scanf("%d %d",&s,&d);

for(a=s,b=0;a>0,b<s;a--,b++){

if(a-b==d)

break;

}

if(a==0 && b==s){printf("impossible\n");}

else{printf("%d %d\n",a,b);}

}

return 0;

}

#include

ReplyDelete@Rayhan Roman

This comment has been removed by the author.

ReplyDeletewhy is it wrong answer? i did not check for s + d % 2 == 0

ReplyDelete#include

using namespace std;

void compute_scores(int s, int d){

int a1 = 0 ;

int a2 = 0 ;

a1 = (s+d)/2 ;

a2 = s - a1 ;

if( a1 < 0 || a2 < 0) cout << "impossible" <> num_test_cases ;

while( i < num_test_cases ){

cin >> s >> d ;

compute_scores(s,d) ;

i++ ;

}

// your code goes here

return 0;

}