http://codevs.cn/problem/1198/
推导一翻,排好序后,直接上高精度。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int in() { int k = 0, fh = 1; char c = getchar(); for(; c < ‘0‘ || c > ‘9‘; c = getchar()) if (c == ‘-‘) fh = -1; for(; c >= ‘0‘ && c <= ‘9‘; c = getchar()) k = (k << 3) + (k << 1) + c - ‘0‘; return k * fh; } struct node { int l, r, num; bool operator < (const node &A) const { return num < A.num; } } a[1003]; int n, l, r; struct Big { int num[50003], len; Big() {memset(num, 0, sizeof(num)); len = 0;} Big operator * (const int b) const { Big c; for(int i = 1; i <= len; ++i) { c.num[i] += num[i] * b; c.num[i + 1] += c.num[i] / 10; c.num[i] %= 10; } c.len = len; while (c.num[c.len + 1] != 0) { ++c.len; c.num[c.len + 1] = c.num[c.len] / 10; c.num[c.len] %= 10; } return c; } Big operator / (const int b) const { int y = 0; Big c; for(int i = len; i >= 1; --i) { y = y * 10 + num[i]; c.num[i] = y / b; y = y % b; } c.len = len; while (c.num[c.len] == 0 && c.len > 1) --c.len; return c; } bool operator < (const Big &b) const { if (len != b.len) return len < b.len; for(int i = len; i >= 1; --i) if (num[i] != b.num[i]) return num[i] < b.num[i]; return false; } void print() { for(int i = len; i >= 1; --i) putchar(‘0‘ + num[i]); puts(""); } }; int main() { n = in(); l = in(); r = in(); for(int i = 1; i <= n; ++i) a[i].l = in(), a[i].r = in(), a[i].num = a[i].l * a[i].r; sort(a + 1, a + n + 1); Big t, ans, cal; while (l > 0) { t.num[++t.len] = l % 10; l /= 10; } ans.len = -1; for(int i = 1; i <= n; ++i) { cal = t / a[i].r; if (ans < cal) ans = cal; t = t * a[i].l; } ans.print(); return 0; }
QwQ
时间: 2024-11-05 18:56:18