Daily Practice 14th:Codeforces Round #742 (Div. 2)

VP*14;

rating:800--1000--1600

A. Domino Disaster

给出两行中的第一行的字母,根据题目推测第二行的字母。

思路:没有思路,直接做。

AC Code:

#include <bits/stdc++.h>
#pragma GCC optimize(2)

template <typename T>
inline void read(T &x) {
	x = 0;
	int f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0', ch = getchar();
	}
	x *= f;
}

template <typename T>
void write(T x) {
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

#define INF 0x3f3f3f3f
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int t, n;
std::string s;

int main() {
//	freopen("test.in","r",stdin);
//  freopen("output.in", "w", stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	std::cin >> t;
	while (t--) {
		std::cin >> n >> s;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'L')
				std::cout << 'L';
			else if (s[i] == 'R')
				std::cout << 'R';
			else if (s[i] == 'D')
				std::cout << 'U';
			else
				std::cout << "D";
		}
		std::cout << '\n';
	}
	return 0;
}

 B. MEXor Mixup

给出a和b,问最少构造的数组中有几个元素,使得该数组的MEX是a,所有元素的异或和是b。

思路: 因为MEX是a,所以从0~a-1的数组必须存在,这些异或和是确定的,所以可以先预处理前缀异或和ans。若ans^b==0,则说明不需要再加入数字了;若ans^b==a,则说明应该加入一个a,但是显然加入a就不符合条件了,那么就需要用两个数的异或去凑a;若ans^b!=a,则任意加入一个数字就可以满足条件。

AC Code:

#include <bits/stdc++.h>
#pragma GCC optimize(2)

template <typename T>
inline void read(T &x) {
	x = 0;
	int f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0', ch = getchar();
	}
	x *= f;
}

template <typename T>
void write(T x) {
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

#define INF 0x3f3f3f3f
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 3e5 + 5;
int t, a, b;
int ans[N];

int main() {
//	freopen("test.in","r",stdin);
//  freopen("output.in", "w", stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	std::cin >> t;
	for (int i = 1; i <= N - 2; i++) {
		ans[i] = ans[i - 1] ^ i;
	}
	while (t--) {
		std::cin >> a >> b;
        int anss=ans[a - 1] ^ b;
		if (anss == 0) {
			std::cout << a << '\n';
		} else if (anss == a) {
			std::cout << a + 2 << '\n';
		} else {
			std::cout << a + 1 << '\n';
		}
	}
	return 0;
}

os:位运算妙啊!

C. Carrying Conundrum

给出一种加法方式,进位是向隔一位加1,给出一个以该方式做加法之后的结果,问有几种组合使得结果为该数。

思路:隔位进位,所以相邻位的结果不互相影响,所以可以把隔一位取出来,组成的数做乘法即可,注意若其中一个数为0,则需要减去。

AC Code:

#include <bits/stdc++.h>
#pragma GCC optimize(2)

template <typename T>
inline void read(T &x) {
	x = 0;
	int f = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0', ch = getchar();
	}
	x *= f;
}

template <typename T>
void write(T x) {
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

#define INF 0x3f3f3f3f
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 105;
int t, n;
int a[N];

int main() {
//	freopen("test.in","r",stdin);
//  freopen("output.in", "w", stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	std::cin >> t;
	while (t--) {
		std::cin >> n;
		int cnt = 0;
		while (n) {
			a[++cnt] = n % 10;
			n /= 10;
		}
		ll ans1 = 0, ans2 = 0;
		for (int i = cnt; i >= 1; i--) {
			if (i & 1)
				ans1 = ans1 * 10 + a[i];
			else
				ans2 = ans2 * 10 + a[i];
		}
		std::cout << (ans1 + 1)*(ans2 + 1) - 2 << '\n';
	}
	return 0;
}

若有错误请指教,谢谢!

orzorz

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值