1. 程式人生 > 其它 >CF1567 Codeforces Round #742(Div.2)

CF1567 Codeforces Round #742(Div.2)

A.

模擬即可

B.

0~a-1要用a個數,判一下異或字首和是不是a,是a的話答案a+2,否則a+1.

// Problem: B. MEXor Mixup
// Contest: Codeforces - Codeforces Round #742 (Div. 2)
// URL: https://codeforces.ml/contest/1567/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 7;
#define ll long long
int rd() {
    int s = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') {s = s * 10 + c - '0'; c = getchar();}
    return s * f;
}
int n, m, k, tot, a, b, sum[2*maxn];
int main() {
	int T = rd();
	for (int i = 1; i <= 600000; i++) {
		sum[i] = sum[i-1] ^ i;
		//printf("sum[%d]==%d\n", i, sum[i]);
	}
	while(T--) {
		a = rd(); b = rd();
		if (sum[a-1] == b) {
			printf("%d\n", a);
			continue;
		}
		int ans = 999999999;
		if ((sum[a-1]^b)==a) ans = min(ans, a+2);
		else ans = min(ans, a+1);
		printf("%d\n", ans);
	}
}

C

奇偶位分開考慮,他們互不影響

// Problem: C. Carrying Conundrum
// Contest: Codeforces - Codeforces Round #742 (Div. 2)
// URL: https://codeforces.ml/contest/1567/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
#define ll long long
int rd() {
    int s = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') {s = s * 10 + c - '0'; c = getchar();}
    return s * f;
}
int n, m, k, tot, stk[maxn], top, a, b;
int main() {
	int t = rd();
	while (t--) {
		n = rd();
		int tmp = n;
		top = 0;
		while (tmp) {
			stk[++top] = tmp % 10;
			tmp /= 10;
		}
		a = b = 0;
		for (int i = top; i >= 1; i--) {
			if (i & 1) {
				a = a * 10 + stk[i];
			} else {
				b = b * 10 + stk[i];
			}
		}
		int ans = 0;
		if (b == 0) { 	//a != 0
			ans = a - 1;
		} else if (a == 0) {
			ans = b - 1;
		} else {
			ans = (a+1)*(b+1)-2;
		}
		printf("%d\n", ans);
	}
	
}

D

場上沒做出來,每次貪心地取出能取出的最高位的1即可(這樣取不會導致退位(用的1更少),如果一開始取一個s-(n-1)和n個1有可能退位。)。

// Problem: CF1567D Expression Evaluation Error
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/CF1567D
// Memory Limit: 250 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
#define ll long long
int n, m, k, tot, a[maxn];
int rd() {
	int s = 0, f = 1; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') {s = s * 10 + c - '0'; c = getchar();}
	return s * f;
}
int s;
int main() {
	int T = rd();
	while (T--) {
		s = rd(); n = rd();
		//輸出第k個數後要保證剩下的數的和>=n-k
		//保證每次輸出的是能輸出的最高位
		int c = s, p = 1000000000;
		while (n > 1) {
			while (s - p < n-1) p /= 10;
			printf("%d ", p);
			s -= p;
			n--;
		}
		printf("%d\n", s);
	}
	return 0;
}