zoukankan      html  css  js  c++  java
  • luogu1208 [USACO1.3]混合牛奶 Mixing Milk

    https://www.luogu.com.cn/problem/P1208

    #include<bits/stdc++.h>
    using namespace std;
    
    struct farmer{
        int price;
        int amount;
    }; 
    
    struct farmer a[5050];
    
    bool cmp(farmer x,farmer y)
    {
        return x.price<y.price;
    }
    int main()
    {
        int n,m;
        cin>>n>>m;//n,m表示需要牛奶的总量,和提供牛奶的农民个数
        int cnt=0;//计数器 
        int cur=0;//现在牛奶总量 
        int ans=0;//费用 
        for(int i=0;i<m;i++)
        {
            scanf("%d",&a[i].price);//pi,ai,表示第 i 个农民牛奶的单价,和农民 i 一天最多能卖出的牛奶量 
            scanf("%d",&a[i].amount);
        }
        sort(a,a+m,cmp);
        while(n>cur)
        {
            cur+=a[cnt].amount;
            if(cur<n)
            ans+=a[cnt].amount*a[cnt].price;
            else 
            ans+=(n-(cur-a[cnt].amount))*a[cnt].price;
            cnt++;
        }
        cout<<ans;
        return 0;
    }
  • 相关阅读:
    Excel VB Script
    Excel Text Converter as C# Format
    快捷键
    如何使用 MasterPage
    Excel 오른쪽버튼 윗주
    Oracle Hints
    ASP.NET 弹出窗口
    Log4Net
    word 修改 表宽度
    While 나가는 법
  • 原文地址:https://www.cnblogs.com/cyfe67373/p/12419745.html
Copyright © 2011-2022 走看看