20年第一次选拔赛题解

A Help Me!!!

#include <bits/stdc++.h>
using namespace std;
int main() {
    
    
	char a[105], b;
	scanf("%[^\n]", a);
	int len = strlen(a);
	for(int i = 0; i < len; ++i) {
    
    
		if(a[i] == ' ') b = ' ';
		else if(i + 2 < len && a[i + 2] == '#')
			b = (a[i] - '0') * 10 + a[i + 1] - '0' + 'a' - 1, i += 2;
		else
			b = a[i] - '0' + 'a' - 1;
		putchar(b);
	}
	return 0;
}

B 任意数
原题

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;
ll ksm(ll a, ll b) {
    
    
	ll ans = 1;
	while(b) {
    
    
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans % mod;
}
int main() {
    
    
	ll n, m;
	cin >> n >> m;
	cout << (ksm(2, m) * (n + 1) % mod - 1) % mod;
	return 0;
}

C 小L的光图

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    
    
	ll n, p, k, ans = 0;
	cin >> n >> p >> k;
	cout << (k % n * p) % n;
	return 0;
}

D 小L求偶

#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
    
    
	int n, ans = 0;
	cin >> n;
	for(int i = 0; i < n; ++i) {
    
    
		scanf("%d", &a[i]);
		if(a[i] % 2 == 0) ans += a[i];
	}
	for(int i = 0; i < n; ++i) {
    
    
		int val, idx;
		scanf("%d%d", &val, &idx);
		if(a[idx] % 2 == 0) ans -= a[idx];
		a[idx] += val;
		if(a[idx] % 2 == 0) ans += a[idx];
		printf("%d\n", ans);
	}
	return 0;
}

E 小L的表达式

#include <bits/stdc++.h>
using namespace std;
int main() {
    
    
	char c, pc ='(';
	bool pre = 0, now = 0;
	while((c = getchar()) && c != '\n') {
    
    
		if(isdigit(c) || (pc == '(' && (c == '-' || c == '+')) || c == '.') {
    
    
			now = 1;
			putchar(c);
		}
		else {
    
    
			now = 0;
			if(pre != now) putchar('\n');
   			putchar(c);
   			putchar('\n');
		}
		pre = now;
		pc = c;
	}
	return 0;
}

F 可恶的小J

#include <bits/stdc++.h>
#define dx (x + dir[i])
#define dy (y + dir[i + 1])
using namespace std;
typedef struct {
    
    
	int x, y;
	int t, s; // 体力,时间
} node;
int dir[] = {
    
    0, 1, 0, -1, 0};
char a[205][205];
int vis[205][205];
int main() {
    
    
	memset(vis, -1, sizeof vis);
	int m, n, t;
	cin >> m >> n >> t;
	queue<node> q;
	for(int i = 0; i < m; ++i) {
    
    
		scanf("%s", a[i]);
		for(int j = 0; j < n; ++j)
			if(a[i][j] == '@')
				q.push({
    
    i, j, t, 0}), vis[i][j] = 0;
	}
	int flag = -1;
	while(!q.empty()) {
    
    
		auto pir = q.front();
		q.pop();
		int x = pir.x, y = pir.y;
		int t = pir.t, s = pir.s + 1;
		for(int i = 0; i < 4; ++i) {
    
    
			if(dx < 0 || dy < 0 || dx >= m || dy >= n || vis[dx][dy] >= t)
				continue;
			if(a[dx][dy] == '+') {
    
    
				flag = s;
				break;
			}
			else if(a[dx][dy] == '#') {
    
    
				vis[dx][dy] = t - 1;
				q.push({
    
    dx, dy, t - 1, s});
			}
			else if(a[dx][dy] == '*') {
    
    
				vis[dx][dy] = t;
				q.push({
    
    dx, dy, t, s});
			}
		}
		if(~flag) break;
	}
	cout << flag;
	return 0;
}

G 敌对的小L和小J

#include <bits/stdc++.h>
using namespace std;
int a[1005];
bool check(int x, int y) {
    
    
	if(__gcd(x, y) == 1) return 1;
	return 0;
}
int main() {
    
    
	int n, ans = 0;
	cin >> n;
	for(int i = 0; i < n; ++i) {
    
    
		cin >> a[i];
		for(int j = 0; j < i; ++j) {
    
    
			if(check(a[i], a[j])) {
    
    
				ans++;
			}
		}
	}
	cout << ans;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41829380/article/details/108553127
今日推荐