- Code: Select all
2 3
-1
7 11
I got WA, but I think the following answer should also be valid. Am I right?
- Code: Select all
2 3
-1
11 15
Moderator: Board moderators
2 3
-1
7 112 3
-1
11 15brianfry713 wrote:For the third case, c=3 and d=15. The correct answer is a=7 and b=11. For your output of a=11 and b=15, a&b=11 which doesn't equal c.
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <iostream>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
long long c, d, a, b, andd, orr, diff=0, MIN=2147483648;
cin>>c>>d;
int fag=0, maxx=max(c,d);
for(int i=maxx ; i>=0 ; i--)
{
for(int j=maxx ; j>=0 ; j--)
{
andd= i&j;
orr = i|j;
if(c==andd && d==orr)
{
diff=j-i;
if(diff<0) diff=diff*(-1);
if(diff<MIN){
a=i; b=j;
MIN=diff;
}
fag=1;
}
}
}
if(a>b){
long long tmp=a;
a=b;
b=tmp;
}
if(fag==0)
printf("-1\n");
else
cout<<a<<" "<<b<<endl;
}
return 0;
}
Users browsing this forum: No registered users and 1 guest