3 条题解

  • 1
    @ 2023-12-24 11:55:35

    ACAC CodeCode

    #include <bits/stdc++.h>
    #define ll long long
    #define re register int
    #define Rep(x, a, b) for (int x = a; x <= b; x++)
    #define Dep(x, a, b) for (int x = a; x >= b; x--)
    #define MAXN 100005
    using namespace std;
    struct T
    {
        int d, t;
    }a[MAXN];
    ll p[MAXN], ans;
    int n;
    inline bool cmp(T x, T y) { return (double)x.d / x.t * 1.0 > (double)y.d / y.t * 1.0; }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        Rep(i, 0, n - 1)
            cin >> a[i].t >> a[i].d;
        sort(a, a + n, cmp);
        p[0] = a[0].d;
        Rep(i, 1, n - 1)
            p[i] = p[i - 1] + a[i].d;
        Rep(i, 0, n - 1)
            ans += (p[n - 1] - p[i]) * a[i].t * 2;
        cout << ans << endl;
        return 0;
    }
    
    • 0
      @ 2023-12-20 18:15:32
      #include<bits/stdc++.h>
      using namespace std;
      int n;
      struct node
      {
          int t,d;
      }a[100001];
      bool cmp(node x,node y)
      {
          return x.t*y.d<y.t*x.d;
      }
      int main()
      {
          cin>>n;
          for(int i=1;i<=n;i+=1)
          {
              cin>>a[i].t>>a[i].d;
          }
          sort(a+1,a+n+1,cmp);
          long long ans=0,T=0;
          for(int i=1;i<=n;i+=1)
          {
              ans+=T*a[i].d;
              T+=2*a[i].t;
          }
          cout<<ans;
      }
      

      AC代码,请放心食用。

      • 0
        @ 2023-12-5 13:49:25
        #include<bits/stdc++.h>
        int n,m,k,s,t;
        struct node
        {
            int t,d;
        }a[100001];
        bool cmp(node x,node y)
        {
            return x.t*y.d<y.t*x.d;
        }
        int main()
        {
            std::cin>>n;
            for(int i=1;i<=n;i+=1)std::cin>>a[i].t>>a[i].d;
            std::sort(a+1,a+n+1,cmp);
            long long ans=0,T=0;
            for(int i=1;i<=n;i+=1)
            {
                ans+=T*a[i].d;
                T+=2*a[i].t;
            }
            std::cout<<ans;
        }
        
        • 1

        信息

        ID
        561
        时间
        1000ms
        内存
        125MiB
        难度
        4
        标签
        递交数
        171
        已通过
        84
        上传者