(复习次数:1)XOR Game——Noobs Round #2 (Div. 4) by Rudro25

https://codeforces.com/problemset/gymProblem/102942/D
D. XOR Game
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Alice and Bob are playing a game.

First Alice will choose two integers a and b (a≤b). Then Bob will take two integers c and d (1≤c≤a,1≤d≤b).

Score of Alice will be (a⊕b) and score of Bob will be (c⊕d), where ⊕ denotes the bitwise xor operation.

If the score of Bob is strictly greater than the score of Alice then Bob wins, otherwise Alice wins.

You know the two integers a and b that Alice chose. Determine if it is possible to choose some c and d for Bob to win.

Input
The first line contains an integer t (1≤t≤102) — the number of test cases in the input.

Then t test cases follow.

Each test case is a line containing two integers a and b (2≤a,b≤106,a≤b).

Output
For each test case, If Bob has a winning strategy print Yes, otherwise No.

You can print each character in any case.

Example
inputCopy
3
2 2
2 4
6 10
outputCopy
Yes
No
Yes
Note
In the first test, the score of Alice is 0. Bob can choose c=1 and d=2 to get a score of 3 to win.

In the second test, we can show that whatever Bob chooses, he will always lose.
二进制异或,找到规律就很简单:结果为0的有机会,改后不会更大的就可以

#include<stdio.h>
#include<string.h>
#define min(a,b) a<b?a:b
#define N 30
int a0[N],b0[N],sa0[N],c0[N],d0[N];
void put(int x,int*x0,int &i){
	for(i=0;x;i++){
		x0[i]=x%2;
		x/=2;
	}
}
int change(int y0[],int x0[],int i,int cnt){
	memcpy(y0,x0,sizeof(int)*cnt);//注意x0字节数为8 
	y0[i]^=1;
	int res=0;
	for(int j=cnt-1;j>=0;j--){
		res*=2;
		res+=y0[j];
	}
	return res;
}
int main(){
	int t;
	scanf("%d",&t);
	int a,b,c,d;
	while(t--){
		memset(a0,0,sizeof(a0));
		memset(b0,0,sizeof(b0));
		memset(sa0,0,sizeof(sa0));
		scanf("%d%d",&a,&b);
		int sa=a^b;
		int cnta,cntb,cntsa;
		put(a,a0,cnta);
		put(b,b0,cntb);
		put(sa,sa0,cntsa);
		int cnt=min(cnta,cntb);
		int flag=0;
		for(int i=0;i<cnt;i++){
			if(sa0[i]==0){
				c=change(c0,a0,i,cnta);
				d=change(d0,b0,i,cntb);
				if(c<=a||d<=b){
					printf("Yes\n");
					flag=1;
					break;					
				}
			}
		}
		if(flag==0){
			printf("No\n");
		}
	}
	return 0;
} 
/*
	010
	100
	110
	011<=010或101<=100,可以
	否则,继续 
*/ 

复习:
5/19
//发现:若有一位双1,即可改大,不然无法改大

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
FILE*fp=freopen("text.in","r",stdin);
#endif
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int a,b;
		bitset<30>ba,bb;
		scanf("%d%d",&a,&b);
		ba=a;
		bb=b;
		bool flag=false;
		for(int i=0;i<30;i++){
			if(ba.test(i)&&bb.test(i)){//发现:若有一位双1,即可改大,不然无法改大 
				flag=true;printf("Yes\n");break;
			}
		}
		if(!flag)printf("No\n");
	} 
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值