The 2024 International Collegiate Programming Contest in Hubei Province, China
A - Long Live
题意
思路
当 \(a=1\) 时,\(ab\) 最大
代码
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;
const int mxn = 1e6 + 10;
void solve()
{
    int x, y;
    cin >> x >> y;
    cout << 1 << " " << x * y / (__gcd(x, y) * __gcd(x, y)) << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int __ = 1;
    cin >> __;
    while (__--) solve();
    return 0;
}
B - Nana Likes Polygons
题意
思路
显然要选\(3\)个点组成三角形,数据很小直接枚举顶点,向量叉积算面积
代码
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;
const int mxn = 1e6 + 10;
void solve()
{
	int n;
	cin >> n;
	vector<pii> a(n);
	for (auto& [x, y] : a)
	{
		cin >> x >> y;
	}
	double ans = 1e18;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i == j) continue;
			for (int k = 0; k < n; k++)
			{
				if (i == k || j == k) continue;
				auto [x1, y1] = a[i];
				auto [x2, y2] = a[j];
				auto [x3, y3] = a[k];
				// 向量
				double X1 = 1.0 * x1 - x2;
				double Y1 = 1.0 * y1 - y2;
				double X2 = 1.0 * x1 - x3;
				double Y2 = 1.0 * y1 - y3;
				double area = fabs(X1 * Y2 - X2 * Y1) / 2;
				if (area >= 1e-6) ans = min(ans, area);
			}
		}
	}
	cout << fixed << setprecision(6) << (ans == 1e18 ? -1 : ans) << endl;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int __ = 1;
	cin >> __;
	while (__--) solve();
	return 0;
}
E - Spicy or Grilled?
题意
思路
算
代码
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;
const int mxn = 1e6 + 10;
void solve()
{
	int n, x, a, b;
	cin >> n >> x >> a >> b;
	cout << x * b + (n - x) * a << endl;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int __ = 1;
	cin >> __;
	while (__--) solve();
	return 0;
}
G - Genshin Impact Startup Forbidden II
题意
思路
答奋模拟说是,fzb爆写\(1h^{++}\)
代码
点击查看代码
#include<bits/stdc++.h>
#define int long long
#define PII pair<int, int> 
#define endl '\n'
#define inf 1e18
using namespace std;
int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
void solve() {
    int n;
    cin >> n;
    vector<vector<int> > G(20, vector<int>(20));
    vector<int> f(20 * 20);
    for (int i = 1; i <= 19; ++i) {
        for (int j = 1; j <= 19; ++j) {
            int aim = 19 * (i - 1) + j;
            f[aim] = aim;
        }
    }
    function<int(int)> find = [&](int x) {
        if (f[x] == x) return x;
        return f[x] = find(f[x]);
    };
    vector<int> sum(20 * 20);
    
    auto merge = [&](int u, int v) {
        u = find(u);
        v = find(v);
        if (u == v) return;
        sum[v] += sum[u];
        sum[u] = 0;
        f[u] = v;
    };
    vector<vector<int> > sta(20, vector<int>(20));
    auto check = [&](int x, int y) {
        return (x >= 1 && x <= 19 && y >= 1 && y <= 19);
    };
    for (int T = 1; T <= n; ++T) {
        int x, y;
        cin >> x >> y;
        set<int> ord;
        if (T & 1) sta[x][y] = 1;
        else sta[x][y] = 2;
        int flag = sta[x][y];
        int aim = (x - 1) * 19 + y;
        f[aim] = aim;
        sum[aim] = 0;
        for (int i = 0; i < 4; ++i) {
            int cx = x + dx[i];
            int cy = y + dy[i];
            if (!check(cx, cy)) continue;
            if (!sta[cx][cy]) {
                sum[aim]++;
            }
            else {
                int u = (cx - 1) * 19 + cy;
                u = find(u);
                sum[u]--;
            }
        }
        for (int i = 0; i < 4; ++i) {
            int cx = x + dx[i];
            int cy = y + dy[i];
            if (!check(cx, cy)) continue;
            if (sta[cx][cy] == sta[x][y]) {
                int v = (cx - 1) * 19 + cy;
                merge(aim, v);
                aim = find(aim);
            }
        }
        for (int i = 0; i < 4; ++i) {
            int cx = x + dx[i];
            int cy = y + dy[i];
            if (!check(cx, cy)) continue;
            if (sta[cx][cy] && sta[cx][cy] != sta[x][y]) {
                int u = (cx - 1) * 19 + cy;
                u = find(u);
                if (sum[u] == 0) ord.insert(u);
            }
        }
        int sum1 = 0, sum2 = 0;
        for (int xx = 1; xx <= 19; ++xx) {
            for (int yy = 1; yy <= 19; ++yy) {
                if (!sta[xx][yy]) continue;
                int u = (xx - 1) * 19 + yy;
                if (ord.count(find(u))) {
                    for (int k = 0; k < 4; ++k) {
                        int cx = xx + dx[k];
                        int cy = yy + dy[k];
                        if (!check(cx, cy)) continue;
                        int v = (cx - 1) * 19 + cy;
                        v = find(v);
                        if (sta[cx][cy] && sta[cx][cy] == sta[x][y]) {
                            sum[v]++;
                        }
                    }
                    sta[xx][yy] = 0;
                    flag == 1 ? sum2++ : sum1++;
                    f[u] = u;
                    sum[u] = 0;
                }
            }
        }
        aim = find(aim);
        if (sum[aim] == 0) {
            for (int xx = 1; xx <= 19; ++xx) {
                for (int yy = 1; yy <= 19; ++yy) {
                    if (!sta[xx][yy]) continue;
                    int u = (xx - 1) * 19 + yy;
                    if (find(u) == aim) {
                        for (int k = 0; k < 4; ++k) {
                            int cx = xx + dx[k];
                            int cy = yy + dy[k];
                            if (!check(cx, cy)) continue;
                            int v = (cx - 1) * 19 + cy;
                            v = find(v);
                            if (sta[cx][cy] && sta[cx][cy] != sta[x][y]) {
                                sum[v]++;
                            }
                        }
                        sta[xx][yy] = 0;
                        flag == 1 ? sum1++ : sum2++;
                        f[u] = u;
                        sum[u] = 0;
                    }
                }
            }
        }
        cout << sum1 << ' ' << sum2 << endl;
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
H - Genshin Impact Startup Forbidden III
题意
思路
格子中鱼的数量只会是 \(0、1、2、3\),即把鱼的数量压成四进制
代码
点击查看代码
#include<bits/stdc++.h>
#define int long long
#define PII pair<int, int> 
#define endl '\n'
#define inf 1e18
using namespace std;
struct node {
    int x, y, cnt;
};
int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> p4(15);
    p4[0] = 1;
    for (int i = 1; i <= 10; ++i) {
        p4[i] = p4[i - 1] * 4;
    }
    vector<vector<int> > mp(n + 1, vector<int>(m + 1, 0));
    vector<node> t(k + 1);
    int now = 0;
    for (int i = 1; i <= k; ++i) {
        int x, y, cnt;
        cin >> x >> y >> cnt;
        now += p4[i - 1] * cnt;
        t[i] = { x, y, cnt };
        mp[x][y] = i;
    }
    vector<int> f(p4[k], inf);
    f[now] = 0;
    auto check = [&](int x, int y) {
        return (x >= 1 && x <= n && y >= 1 && y <= m);
    };
    for (int i = now; i; --i) {
        if (f[i] == inf) continue;
        for (int j = 1; j <= k; ++j) {
            if (i / p4[j - 1] % 4) {
                auto [x, y, cnt] = t[j];
                int st = i;
                int p = mp[x][y];
                if (p && st / p4[p - 1] % 4) {
                    st -= p4[p - 1];
                }
                for (int s = 0; s < 4; ++s) {
                    int cx = x + dx[s];
                    int cy = y + dy[s];
                    if (!check(cx, cy)) continue;
                    p = mp[cx][cy];
                    if (p && st / p4[p - 1] % 4) {
                        st -= p4[p - 1];
                    }
                }
                f[st] = min(f[st], f[i] + 1);
                for (int s = 0; s < 4; ++s) {
                    int cx = x + dx[s];
                    int cy = y + dy[s];
                    if (!check(cx, cy)) continue;
                    st = i;
                    p = mp[cx][cy];
                    if (p && st / p4[p - 1] % 4) {
                        st -= p4[p - 1];
                    }
                    for (int a = 0; a < 4; ++a) {
                        int nx = cx + dx[a];
                        int ny = cy + dy[a];
                        if (!check(nx, ny)) continue;
                        p = mp[nx][ny];
                        if (p && st / p4[p - 1] % 4) {
                            st -= p4[p - 1];
                        }
                    }
                    f[st] = min(f[st], f[i] + 1);
                }
            }
        }
    }
    cout << f[0] << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
J - Points on the Number Axis A
题意
思路
随机取两个点,即每个点被取到的概率相等,最后一个点的期望位置就是 \(\frac 1 n{\sum_{i=1}^n x_i}\)
代码
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;
const int mxn = 1e6 + 10;
const int mod = 998244353;
int qpow(int base, int a)
{
	int res = 1;
	while (a)
	{
		if (a & 1) res = res * base % mod;
		base = base * base % mod;
		a >>= 1;
	}
	return res;
}
int inv(int x)
{
	return qpow(x, mod - 2) % mod;
}
void solve()
{
	int n, sum = 0, x;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		sum = (sum + x) % mod;
	}
	cout << sum * inv(n) % mod << endl;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int __ = 1;
	//cin >> __;
	while (__--) solve();
	return 0;
}
L - LCMs
题意
思路
非互质特判见代码;对于互质的 \(a\) 与 \(b\),设二者最小质因数为 \(p\) 与 \(q\),最终的答案就是从 \(a\) 出发, 以 \(2、p、q\) 作为中转点的最短路径
代码
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;
const int mxn = 1e6 + 10;
const int mod = 998244353;
int f(int x)
{
	for (int i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0) return i;
	}
	return x;
}
void solve()
{
	int a, b;
	cin >> a >> b;
	if (a == b) cout << 0 << endl;
	else if (b % a == 0) cout << b << endl;
	else if (gcd(a, b) != 1) cout << a + b << endl;
	else
	{
		int p = f(a), q = f(b), ans = 1e18;
		ans = min(ans, lcm(a, b));
		ans = min(ans, lcm(a, p) + lcm(p, b));
		ans = min(ans, lcm(a, q) + lcm(q, b));
		ans = min(ans, lcm(a, 2) + lcm(2, b));
		ans = min(ans, lcm(a, p) + lcm(p, q) + lcm(q, b));
		ans = min(ans, lcm(a, p) + lcm(p, 2) + lcm(2, b));
		ans = min(ans, lcm(a, 2) + lcm(2, q) + lcm(q, b));
		ans = min(ans, lcm(a, p) + lcm(p, 2) + lcm(2, q) + lcm(q, b));
		cout << ans << endl;
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int __ = 1;
	cin >> __;
	while (__--) solve();
	return 0;
}









                
            
        
浙公网安备 33010602011771号