Codeforces Round 899 (Div. 2)A~C

今天先补A~C啦,D题明天再说

Problem - A - Codeforces

模拟题,easy

#include<bits/stdc++.h>

using namespace std;
const int N = 100010;
using ll = long long;

void solve() {
    int n; cin >> n;
    vector<int>a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int ans = 0;

    for (int i = 0; i < n; i++) {
        ans++;
        if (ans == a[i]) {
            ans++;
        }
    }
    cout << ans << '\n';
}


signed main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin >> t;

    while (t--)
        solve();
}

B题

Problem - B - Codeforces

暴力,数字1~50,枚举,如果要让某一个数不存在S中,S中还有的不同的数的数量,代码写得比较丑

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 1e9 + 5;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

void solve(){
	int n; cin >> n;
	int s[55][55] = { };
	int s2[55][55] = { };
	int idx[55]={ };
	bool fg[55] = { };
	bool fg2[55] = { };
	for (int i = 1; i <= n; i++) {
		int k; cin >> k;
		idx[i] = k;
		for (int j = 1; j <= k; j++) {
			int m; cin >> m;
			s[i][m]++;
			fg[m] = true;
			s2[i][j] = m;
		}
	}
	int ans = 0; int t = 0;
	for (int i = 1; i <= 50; i++) {
		memset(fg2, 0, sizeof fg2);
		t = 0;
		if (!fg[i])continue;
		for (int j = 1; j <= n; j++) {
			if (s[j][i]) { continue; }
			for (int k = 1; k <= idx[j]; k++) {
				if (!fg2[s2[j][k]]) {
					t++;
					fg2[s2[j][k]] = 1;
				}
			}
		}
		ans = max(ans, t);
	}
	cout << ans << '\n';
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}

C题,没开long long, WA2了,好吧!

Problem - C - Codeforces

假设我们一定选第i个,那么第i个后面的正整数就都能取得

开个后缀和优化一下,写后缀和数组时就把负数当成0就行

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 1e9 + 5;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

void solve(){
	int n; cin >> n;
	vector<ll>a(n + 1);
	vector<ll>suf(n + 2);//suffix数组

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	for (int i = n; i >= 1; i--) {
		suf[i] = suf[i + 1] + max(1ll*0, a[i]);
	}

	ll ans = 0;

	for (int i = 1; i <= n; i++) {
		ans = max(ans, (i & 1) * a[i] + suf[i + 1]);
	}

	cout << ans << '\n';
}
signed main(){

	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值