2019-CCPC-网络赛-1001 ^&^

题目分析:找出最小的值c使(a^c)&(b^c)最大。

代码:

#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
	long long a, b;
	int t;
	scanf("%d", &t);
	while(t--){
		scanf("%lld%lld", &a, &b);
		if((a&b)==0)
			printf("%lld\n", min(a, b));
		else
			printf("%lld\n", a&b);		
	}
	return 0;
} 

待验证:

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
/*
(A^C)&(B^C)=(A&B)^C
(A&B)如果与C相等时则为0,不相等时则为1. 
*/
int main(){
	long long t,flag;
	long long a,b;
	cin>>t;
	while(t--){
		cin>>a>>b;
		flag=a&b;
		//cout<<flag<<endl;
		/*for(int i=1;i<=flag+10;i++){
			int x=flag ^ i;
			cout<<"flag="<<flag<<",c="<<i<<",res="<<x<<endl;
		}*/
		if(flag!=0) cout<<flag<<endl;
		else cout<<1<<endl;
	} 
} 

 

全部评论

相关推荐

真起不了响亮的名字:九月份人家投秋招你投实习嘛,会不会有点晚了,算你九月份直接上岗,实习三个月后一月初去和别人抢秋招补录还是备战春招啊更别说休息一个月后还要重新复习八股和算法
点赞 评论 收藏
分享
陆续:不可思议 竟然没那就话 那就我来吧 :你是我在牛客见到的最美的女孩
点赞 评论 收藏
分享
07-08 13:48
门头沟学院 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务