20,寄
查看原帖
20,寄
912248
FuckYouJinhai楼主2023/4/22 14:12
#include <bits/stdc++.h>
using namespace std;
using bigint = vector<int>;

#define int long long

bigint operator+ (bigint a, bigint b) {
	bigint c;
	int t = 0;
	for (int i = 0; i < max(a.size(), b.size()); ++i) {
		if (i < a.size())
			t += a[i];
		if (i < b.size())
			t += b[i];
		c.push_back(t % 10);
		t /= 10;
	}
	if (t)
		c.push_back(1);
	return c;
}

bigint operator* (bigint a, int b) {
	bigint c;
	int t = 0;
	for (int i = 0; i < a.size() || t; ++i) {
		if (i < a.size())
			t += a[i] * b;
		c.push_back(t % 10);
		t /= 10;
	}
	return c;
}

bigint operator/ (bigint a, int b) {
	bigint c(a.size(), 0);
    int t = 0;
    for (int i = a.size() - 1; i >= 0; --i) {
        t = t * 10 + a[i];
        c[i]=t / b;
        t %= b;
    }
    while(c.size() && c[c.size() - 1] == 0)
        c.pop_back();
    return c;
}

bool operator< (bigint a, bigint b) {
	if (a.size() < b.size())
		return 1;
	else if (a.size() == b.size()) {
		for (int i = a.size() - 1; i >= 0; --i) {
			if (a[i] < b[i])
				return 1;
			else if (a[i] > b[i])
				return 0;
		}
		return 0;
	} else
		return 0;
}

int n, A, B;
int a[10010], b[10010], p[10010];
bigint S, maxn;

signed main () {
	S.push_back(1);
	cin >> n >> A >> B;
	S = S * A;
	for (int i = 1; i <= n; ++i)
		cin >> a[i] >> b[i];
	iota(p + 1, p + 1 + n, 1);
	sort(p + 1, p + 1 + n, [](int i, int j) {
		return a[i] * b[i] < a[j] * b[j];
	});
	for (int i = 1; i <= n; ++i) {
		bigint n = S / b[i];
		maxn = maxn < n ? n : maxn;
		S = S * a[i]; 
	}
	for (int i = maxn.size() - 1; i >= 0; --i)
		cout << maxn[i];
	return false;
}

2023/4/22 14:12
加载中...