# 国王游戏

 1 #include <bits/stdc++.h>
2 using namespace std;
3 const int N = 1010;
4 int n;
5 typedef pair<int, int> PII;
6 PII ps[N]; //peoples
7 vector<int> mul(vector<int> a, int b) { //大整数a乘以一个小整数b
8     vector<int> c;
9     int t = 0;
10     for (int i = 0; i < a.size(); i++) {
11         t += a[i] * b;
12         c.push_back(t % 10);
13         t /= 10;
14     }
15     while (t) {
16         c.push_back(t % 10);
17         t /= 10;
18     }
19     return c;
20 }
21 vector<int> div(vector<int> a, int b) { //大整数a除以一个小整数b
22     vector<int> c;
23     bool is_first = false; //为了避免商有很多个0
24     //表示前面是否已经有非零位了
25     int t = 0;
26     for (int i = a.size() - 1; i >= 0; i--) {
27         t = t * 10 + a[i];
28         int x = t / b;
29         if (x || is_first) {
30             is_first = true;
31             c.push_back(x);
32         }
33         t %= b;
34     }
35     reverse(c.begin(), c.end());
36     return c;
37 }
38 vector<int> max_vec(vector<int> a, vector<int> b) { //vector的max函数
39     if (a.size() > b.size()) {
40         return a;
41     }
42     if (a.size() < b.size()) {
43         return b;
44     }
45     for (int i = a.size() - 1; i >= 0; i--) {
46         if (a[i] > b[i]) {
47             return a;
48         } else if (a[i] < b[i]) {
49             return b;
50         }
51     }
52     return a;
53 }
54 void output(vector<int> a) {
55     for (int i = a.size() - 1; i >= 0; i--) {
56         cout << a[i];
57     }
58     cout << endl;
59 }
60 int main() {
61     cin >> n;
62     for (int i = 0; i <= n; i++) { //存储所有人信息
63         int a, b;
64         cin >> a >> b;
65         ps[i] = {a * b, a};
66     }
67     sort(ps + 1, ps + 1 + n);
68     vector<int> A; //存储那个大整数
69     A.push_back(1);
70     vector<int> res; //存储答案
71     res.push_back(0);
72     for (int i = 0; i <= n; i++) { //开始遍历
73         if (i) { //国王不会给自己发奖励，从1开始才会更新答案
74             res = max_vec(res, div(A, ps[i].first / ps[i].second));
75         }
76         A = mul(A, ps[i].second);
77     }
78     output(res);
79     return 0;
80 }

posted @ 2020-11-15 20:55  kyk333  阅读(136)  评论(0编辑  收藏  举报