码风自我感觉良好 求调
查看原帖
码风自我感觉良好 求调
781623
xueruhao楼主2024/11/22 14:50

WA on #10 & #11。

数据下载下来测试,发现#10没输出。

#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define int long long
int n, LEN = 1, ans[N];
struct S
{
    int left, right, sum;
} A[N];
bool cmp(S a, S b)
{
    return a.sum < b.sum;
}
void f1(int x)
{
    for (int i = 1; i <= LEN; i++)
    {
        ans[i] *= A[x].left;
    }
    for (int i = 1; i <= LEN; i++)
    {
        ans[i + 1] += (ans[i] / 10);
        ans[i] %= 10;
    }
    LEN++;
    while (ans[LEN] > 9)
    {
        ans[LEN + 1] += (ans[LEN] / 10);
        ans[LEN] %= 10;
        LEN++;
    }
    if (ans[LEN] == 0)
    {
        LEN--;
        // cout << ":::" << LEN << endl;
    }
}
void f2()
{
    for (int i = LEN; i >= 1; i--)
    {
        ans[i - 1] += ((ans[i] % A[n].right) * 10);
        ans[i] /= A[n].right;
    }
    while (ans[LEN] == 0)
    {
        // cout << "::" << LEN << endl;
        LEN--;
    }
}
signed main()
{
    // freopen("P1080_10.in", "r", stdin);
    scanf("%lld", &n);
    // if(n == 1000){
    //     cout << 1 << endl;
    //     return 0;
    // }

    // freopen("P1080_10.ans", "w", stdout);
    for (int i = 0; i <= n; i++)
    {
        scanf("%lld%lld", &A[i].left, &A[i].right);
        A[i].sum = A[i].left * A[i].right;
    }
    sort(A + 1, A + n + 1, cmp);
    ans[1] = A[0].left;
    for (int i = 1; i < n; i++)
    {
        f1(i);
    }
    // cout << 111 << endl;
    f2();
    // cout << LEN << endl;
    for (int i = LEN; i >= 1; i--)
        cout << ans[i];
    return 0;
}

2024/11/22 14:50
加载中...