#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define LEN 105
using namespace std;
typedef struct node
{
int a;
int b;
int c[LEN];
int ans[LEN];
} node;
void clear(int a[])
{
for (int i = 0; i < LEN; ++i)
{
a[i] = 0;
}
}
void write(int a[])
{
int i;
for (i = LEN - 1; i >= 1; --i)
{
if (a[i] != 0)
break;
}
for (; i >= 0; --i)
{
putchar(a[i] + '0');
}
}
bool cmp(node nd1, node nd2)
{
return nd1.a * nd1.b < nd2.a * nd2.b;
}
bool cmp_high(int a[], int b[])
{
int la, lb;
for (la = LEN; la > 0; --la)
{
if (a[la - 1] != 0)
break;
}
for (lb = LEN; lb > 0; --lb)
{
if (b[lb - 1] != 0)
break;
}
if (la > lb)
return true;
else
{
for (int i = la - 1; i >= 0; --i)
{
if (a[i] > b[i])
return true;
if (a[i] < b[i])
return false;
}
return true;
}
}
void int_to_high(int a, int b[])
{
clear(b);
int cnt = 0;
while (a != 0)
{
b[cnt] = a % 10;
a /= 10;
cnt++;
}
}
bool greater_eq(int a[], int b, int last_dg)
{
if (a[last_dg + 1] != 0)
return true;
if (a[last_dg] >= b)
return true;
else
return false;
}
void div(int a[], int b, int c[])
{
clear(c);
int d[LEN] = {0};
int la, lb = 1;
for (la = LEN; la > 0; --la)
{
if (a[la - 1] != 0)
break;
}
for (int i = 0; i < LEN; ++i)
{
d[i] = a[i];
}
for (int i = la - lb; i >= 0; --i)
{
while (greater_eq(d, b, i))
{
d[i] -= b;
if (d[i] < 0)
{
d[i + 1] -= 1;
d[i] += 10;
}
c[i]++;
}
}
}
void mul(int a[], int b, int c[])
{
clear(c);
for (int i = 0; i < LEN - 1; ++i)
{
c[i] += a[i] * b;
if (c[i] >= 10)
{
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
}
}
int n;
int m[LEN];
int d[LEN];
vector<node> v;
int main()
{
scanf("%d", &n);
for (int i = 0; i <= n; ++i)
{
node nd;
scanf("%d%d", &nd.a, &nd.b);
v.push_back(nd);
}
sort(v.begin() + 1, v.end(), cmp);
clear(v[0].c);
v[0].c[0] = 1;
for (int i = 1; i <= n; ++i)
{
mul(v[i - 1].c, v[i - 1].a, v[i].c);
// write(v[i - 1].c);
// printf("*%d=", v[i - 1].a);
// write(v[i].c);
// printf("\n");
div(v[i].c, v[i].b, v[i].ans);
// write(v[i].c);
// printf("/%d=", v[i].b);
// write(v[i].ans);
// printf("\n");
}
int idx = 0;
for (int i = 1; i <= n; ++i)
{
if (cmp_high(v[i].ans, m))
{
idx = i;
}
}
write(v[idx].ans);
return 0;
}
按照高精度的模板套的,求大佬指导为什么会TLE,以及样例十WA了