提交时间:2024-08-20 21:14:51

运行 ID: 172835

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <queue> #include <cstring> #include <fstream> using namespace std; int sum[50000],ans[50000],t[50000]; int n; struct node { int l,r,lr; }pp[1009]; bool cmp(node x,node y) { if(x.lr != y.lr) return x.lr < y.lr; return x.r < y.r; } void cheng(int x) { for (int i = 1 ; i <= sum[0] ; i ++) sum[i] *= x; for(int i = 1 ; i <= sum[0] ; i ++) { sum[i + 1] += sum[i] / 10; sum[i] %= 10; if (i == sum[0] && sum[sum[0] + 1] != 0) sum[0] ++; } } bool judge() { for (int i = 1 ; i <= t[0] ; i ++) { if (t[i] != ans[i]) return t[i] > ans[i]; } } void solve(int x) { int num = 0,i = sum[0] + 1,s = 0; memset(t,0,sizeof(t)); while (num < x) { -- i; num = num * 10 + sum[i]; } t[0] = i; for (; i >= 1 ; i --) { t[++ s] = num / x; num = num % x * 10 + sum[i - 1]; } if (t[0] > ans[0] || t[0] == ans[0] && judge()) { for (int i = 0 ; i <= t[0] ; i ++) ans[i] = t[i]; } } int main() { cin >> n; for(int i = 0 ; i <= n ; i ++) { cin >> pp[i].l >> pp[i].r; pp[i].lr = pp[i].l * pp[i].r; } sum[1] = pp[0].l; sum[0] = 1; ans[1] = 0; ans[0] = 1; sort(pp + 1,pp + n + 1,cmp); for (int i = 1 ; i <= n ; i ++) { cheng(pp[i].l); solve(pp[i].lr); } for (int i = 1 ; i <= ans[0] ; i ++) i < ans[0] ? cout << ans[i] : cout << ans[i] << endl; return 0; }