2019CCPC网络选拔赛

1001:^&^

题意:求最小的C使(A  xor  C)  &  (B  xor  C)最小

思路:要使(A  xor  C)  &  (B  xor  C)最小,那么它最小只能是零。问题就变成了找到一个C使(A  xor  C)  &  (B  xor  C)为0,当时比赛的时候蒙对了,发现C=A&B,发现倒推是可以证明的,但正推不太会。

代码:

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
    long long m,n;
    scanf("%d%d",&m,&n);
    m=m&n;
    if(m==0)
       cout<<"1"<<endl;
    else
       cout<<m<<endl;
    }
return 0;
}

 

1006:Shuffle Card

题意:给你n个数,从1到n排列,进行m次操作,每次操作都把这个数放到这个数列的第一个位置。

题目很好做,关键是你用什么容器装1-n个数,可以用vector,也可以用stack。有一个问题要注意,就是重复的数要对其进行标记

代码:

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
const int maxn = 1e5;
int a[maxn], b[maxn], temp[maxn];
int main() {
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	memset(temp, 0, sizeof(temp));
	vector<int> ans;
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= m; i++)
		cin >> b[i];
	for (int i = m; i >= 1; i--) {
		if (temp[b[i]] == 1)
			continue;
		ans.push_back(b[i]);
		temp[b[i]] = 1;  //标记
	}
	for (int i = 1; i <= n; i++) {
		if (temp[a[i]] == 1)
			continue;
		ans.push_back(a[i]);
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] << " ";
	}
	//system("pause");
	return 0;
}

1007:Windows Of CCPC

大佬博客:https://blog.csdn.net/qq_41505957/article/details/100043677

代码:

#include<iostream>
#include<cmath>
using namespace std;
void f(int n, int s, int t)
{
	if (n == 2) {
		if (t == 1) {
			if (s == 1)
				cout << "CC";
			else
				cout << "PC";
		}
		else {
			if (s == 1)
				cout << "PP";
			else
				cout << "CP";
		}
		return ;
	}
	int x = s % (n / 2);
	if (x == 0)
		x = n / 2;
	if (t == 1)
	{
		if (s > n / 2)
			f(n / 2, x, 0);
		else
			f(n / 2, x, 1);
		f(n / 2, x, 1);
	}
	else if (t == 0) {
		if (s > n / 2)
			f(n / 2, x, 1);
		else
			f(n / 2, x, 0);
		f(n / 2, x, 0);
	}
}
int main() {
	int n,m;
	cin >> n;
	while (n--) {
		cin >> m;
		m = pow(2, m);
		for (int i = 1; i <= m; i++) {
			f(m, i, 1);
			cout << endl;
		}
	}
	//system("pause");
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值