zoukankan      html  css  js  c++  java
  • POJ 3362 Protecting the Flowers

    这题和金华区域赛A题(HDU 4442)是一样的做法。

    对两个奶牛进行分析,选择两个奶牛总花费少的方式排序。

    bool cmp(const X&a,const X&b)
    {
      return a.t*b.d<b.t*a.d;
    }

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    
    const int maxn=100000+10;
    struct X
    {
        long long t;
        long long d;
    } s[maxn];
    int n;
    
    bool cmp(const X&a,const X&b)
    {
        return a.t*b.d<b.t*a.d;
    }
    
    int main()
    {
        while(~scanf("%d",&n))
        {
            for(int i=1; i<=n; i++) scanf("%lld%lld",&s[i].t,&s[i].d);
            sort(s+1,s+1+n,cmp);
            long long ans=0;
            long long sum=2*s[1].t;
            for(int i=2; i<=n; i++)
            {
                ans=ans+s[i].d*sum;
                sum=sum+2*s[i].t;
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    pymysql
    Mysql
    协程
    线程池
    线程 条件
    线程 事件
    线程
    requests
    Linux 时区不对的解决办法
    Linux 简单命令
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5309568.html
Copyright © 2011-2022 走看看