牛客国庆集训派对Day1

A-Tobaku Mokushiroku Kaiji

A-Tobaku Mokushiroku Kaiji题目链接

水题...不解释

#include <stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 210008;
int a, b, c, d, e, f;
int main() {
	cin >> a >> b >> c >> d >> e >> f;
	cout << min(a, e) + min(b, f) + min(c, d) << endl;
	return 0;
}

C-Utawarerumono

C-Utawarerumono题目链接

官方题解:暴力枚举+EGCD(扩展欧几里得)来判断有无整数

这里只说一下用EGCD(扩展欧几里得算法):常用于判断线性同余方程有无整数解,并求解求解线性同余方程。

定理:对于方程ax+by=c,有整数解的充要条件是c%EGCD(a,b)==0。

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
const int Max = 1e18;
ll ans = 1e18;//ans一定要开在上面,否则会炸!!!!
int a, b, c;
int p1, p2;
int q1, q2;
ll x, y;
int egcd(int a, int b)
{
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	int ans = egcd(b, a%b);
	int tem = x;
	x = y;
	y = tem - a / b*y;
	return ans;
}
int main()
{
	cin >> a >> b >> c >> p1 >> p2 >> q1 >> q2;
	if (a == 0 && b == 0 && c != 0) {
		cout << "Kuon" << endl;
		return 0;
	}
	if (c%egcd(a, b) != 0) {
		cout << "Kuon" << endl;
		return 0;
	}
	for (ll x = -maxn; x <= maxn; x++) {//暴力枚举
		if ((c - a*x) % b == 0) {
			ll y = (c - a*x) / b;
			ll ac = p2*x*x + p1*x + q2*y*y + q1*y;
			ans = min(ans, ac);
		}
	}
	if (ans == Max)
		cout << "Kuon" << endl;
	else
		cout << ans << endl;
	return 0;
}

E-Eustia of the Tarnished Wings

E-Eustia of the Tarnished Wings题目链接

依然水题...

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
typedef long long ll;
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e7+10;
ll n, m;
ll d[maxn];
ll ans = 1;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> d[i];
	}
	sort(d + 1, d + 1 + n);
	for (int i = 2; i <= n; i++) {
		if (abs(d[i] - d[i - 1]) > m)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

未完待续...

猜你喜欢

转载自blog.csdn.net/zsnowwolfy/article/details/82989760