Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round)

A题

没什么好说的,总和一定是0

Problem - A - Codeforces

#include<bits/stdc++.h>

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

void solve(){
	int n; cin >> n;
	vector<int>a(n);
	int ans1 = 0,ans2 = 0;
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		if (a[i] >= 0)
			ans1 += a[i];
		else
			ans2 += abs(a[i]);
	}
	cout << ans2 - ans1 << '\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;
}

B题

村长先告诉给花费最低的人a,a再告诉别的花费小于p的人,他们再告诉别人,如果还有剩下的人,由村长告诉

Problem - B - Codeforces

#include<bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
const int N = 30;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

struct my {
	int a;
	int b;
};

auto cmp(my a, my b) {
	return a.b < b.b;
}

void solve(){
	int n, p; cin >> n >> p;
	vector<my>c(n + 1);

	for (int i = 1; i <= n; i++) {
		cin >> c[i].a;
	}
	for (int i = 1; i <= n; i++) {
		cin >> c[i].b;
	}
	if (n == 1) {
		cout << p << '\n';
		return;
	}

	sort(c.begin() + 1, c.end(),cmp);
	
	ll ans = 0;
	int t = n; int tt=0;
	int cnt = 0;
	t--;
	ans += p;
	for (int i = 1; i <= n; i++) {
		if (c[i].b <= p) {
				tt += c[i].a;
		}
		else
			break;
	}
	if (tt>=t) {
		for (int i = 1; i <= n; i++) {
			if (t > c[i].a) {
				ans += c[i].b * c[i].a;
				t -= c[i].a;
			}
			else {
				ans += c[i].b * t;
				break;
			}
		}
	}
	else {
		t--;
		ans += p;
		for (int i = 1; i <= n; i++) {
			if (p >= c[i].b) {
				ans += c[i].b * c[i].a;
				t -= c[i].a;
			}
			else
				break;
		}
		ans += t * p;
	}
	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题

推一下可以发现,k只可能等于1,2,3,注意判断一下m为n的倍数(m=n不算),当时脑子卡了觉得0~m有m个数,wa了6发

Problem - C - Codeforces

#include<bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
const int N = 30;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

inline void solve(){
	int n, m, k; cin >> n >> m >> k;
	int ans = 0;
	if (k > 3) {
		cout << ans << '\n';
		return;
	}

	if (k == 3) {
		if (m > n) {
			ans = m - n;
			ans -= m / n - 1;
		}
		else
			ans = 0;
	}
	if (k == 1) {
		ans=1;
	}
	if (k == 2) {
		if (m > n) {
			ans += n;
			ans += m / n - 1;
		}
		else
			ans = m ;
	}
	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;
}

别的明天再补了,只能切ABC实属弱鸡

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值