2 条题解

  • 0
    @ 2025-10-8 17:01:57

    by hansang:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    typedef long long LL;
    struct node{LL t, d;} a[N];
    bool cmp(node n1, node n2){
        return n1.t*n2.d < n2.t*n1.d;
    }
    int main(){
        int n; scanf("%d", &n);
        for(int i=1; i<=n; i++){
            scanf("%lld%lld", &a[i].t, &a[i].d);
            a[i].t *= 2;
        }
        sort(a+1, a+n+1, cmp);
        LL sum=0, ans=0;
        for(int i=1; i<=n; i++){
            ans += sum * a[i].d;
            sum += a[i].t;
        }
        printf("%lld\n", ans);
        return 0;
    }
    
    • 0
      @ 2025-10-8 17:01:38

      by hansang:

      #include<bits/stdc++.h>
      using namespace std;
      const int N=1e5+10;
      typedef long long LL;
      struct node{LL t, d;} a[N];
      bool cmp(node n1, node n2){
      	return n1.t*n2.d<n2.t*n1.d;
      }
      int main(){
      	int n; scanf("%d", &n);
      	for(int i=1; i<=n; i++){
      		scanf("%lld%lld", &a[i].t, &a[i].d);
      		a[i].t*=2;
      	}
      	sort(a+1, a+n+1, cmp);
      	LL sum=0, ans=0;
      	for(int i=1; i<=n; i++){
      		ans+=sum*a[i].d;
      		sum+=a[i].t;
      	}
      	printf("%lld\n", ans);
      	return 0;
      }
      • 1

      *【贪心】保护花朵[USACO07JAN] Protecting the Flowers S

      信息

      ID
      2624
      时间
      1000ms
      内存
      128MiB
      难度
      4
      标签
      递交数
      45
      已通过
      22
      上传者