Codeforces Round #742 (Div. 2)

Codeforces Round #742 (Div. 2)

A Domino Disaster (模拟)

模拟

#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
const int N=1e5+100;
char c[N];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	cin>>n;
		cin>>c;
		for(int i=0;i<n;i++)
		{
			if(c[i]=='U') cout<<"D";
			else if(c[i]=='R') cout<<"LR";
			else if(c[i]=='D') cout<<"U";
			else continue;
		}
		puts("");
		
    }
	return 0;
}

B. MEXor Mixup (思维)

题意:
给出a,b。
a : M E X a:MEX a:MEX(数列中未出现的最小数字)
b : M O R b:MOR b:MOR(数列中所有数字的异或和为b)

思路分析:
预处理前缀异或和

设数组C用来储存前缀异或和,那么就可以分出三种情况,
情况一:C[a-1]==b,意味着无需额外的元素就满足了条件二,输出a即可;

情况二:C[a-1]^a==b,意味着所需要的那个元素恰好为不可取的a,那么就需要用另外两个元素异或的结果来替代这个元素,输出a+2;

情况三:C[a-1]!=a,意味着所需要的那个元素可以直接加入数组,所以输出a+1即可。

#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
const int N=3e5+10;
int c[N];
int main()
{
    int t;
    cin>>t;
    
    for(int i=1;i<=N;i++)
    c[i]=c[i-1]^i;
    
    
    while(t--)
    {
    	int a,b;
    	cin>>a>>b;
		if(c[a-1]==b) cout<<a<<endl;
		else if((c[a-1]^a)==b) cout<<a+2<<endl;//if语句中的异或运算要加扩号
    	else cout<<a+1<<endl;
    }
	return 0;
}

  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值