2021“MINIEYE杯”中国大学生算法设计超级联赛-热身赛(2021湘潭全国邀请赛-重现)

A+B Problem

题解:

分两种情况

  • 越界
    可以发现 |a| + |b| + |ans| == 2048
    那么如何搞这个呢
    1.上越界,循环到负数,把他搞到上越界的部分的数,搞成正数,那么外围减去 1024 1024 1024
    2.下越界,循环到正数,把他搞到下越界的部分的数,搞成正数 + 1024 + 1024 +1024,外围减去 1024 1024 1024
    就可以推出来了
  • 不越界
    正常算
    内外 1024 1024 1024相互抵消

AC

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
	int t;
	cin >> t;
	while (t -- ) {
		int a, b;
		cin >> a >> b;
		cout << (a + b + 1024 + 2048) % 2048 - 1024 << endl;
	}
	return 0;
} 

Game

题解

如果只有 − 9 -9 9 操作,那么可以把这些数按 9 9 9 的余数取模,对于 − 99 , − 999 , − 9999..... -99, -999, -9999..... 99,999,9999..... 都是一样的,奇偶性不变,那么为了让数不一样,我们就都减去 9 9 9 ,然后再排序,如果取模后的余数相同的数只有一个就OK,如果不是,那我们就逆推,我们可以最多模几个 9 9 9

伪代码举例:

i.e. 2, 11, 20, 29
i.e. 2, 2, 2, 2

ans = 1 + 2 + 3;
sum[2] = 4;
ans -= 4 * (4 - 1) / 2;
ans = 0;
cout << "B" << endl;

AC

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int a[N];
int sum[10];
int main() {
	int t;
	cin >> t;
	while (t -- ) {
		int n;
		cin >> n;
		LL ans = 0;
		memset(sum, 0, sizeof sum);
		memset(a, 0, sizeof a);
		for (int i = 1; i <= n; i ++ ) {
			cin >> a[i];
			ans += a[i] / 9;
			a[i] %= 9;
		}
		sort(a + 1, a + n + 1);
		for (int i = 1; i <= n; i ++ ) {
			sum[a[i]] ++;
		}
		for (int i = 1; i < 9; i ++ ) {
			ans -= sum[i] * (sum[i] - 1) / 2;
		}
		ans -= sum[0] * (sum[0] + 1) / 2;
		if (ans % 2 == 1) cout << "A" << endl;
		else cout << "B" << endl;
	}
	return 0;
} 

Substring

题解

滑窗,从左到右滑过去就好

AC

#include <bits/stdc++.h>
using namespace std;
int sum[30];
int ops[30];
int main() {
	int t;
	cin >> t;
	while (t -- ) {
		int k;
		cin >> k;
		string str;
		memset(sum, 0, sizeof sum);
		memset(ops, 0, sizeof ops);
		cin >> str;
		int len = str.size();
		int ans = 0;
		int i, j;
		for (i = 0, j = 0; i < len; i ++ ) {
			if (sum[str[i] - 'a'] < k) {
				if (sum[str[i] - 'a'] == 1)
					ops[str[i] - 'a'] = i;
				sum[str[i] - 'a'] ++;
			} else {
				if (k != 1) {
					j = ops[str[i] - 'a'];
				}
				else j = i;
			}
			ans = max(i - j + 1, ans);
		}
		ans = max(ans, i - j);
		cout << ans << endl;
	}
	return 0;
} 
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值