zoukankan      html  css  js  c++  java
  • [Usaco2010 Feb]Chocolate Buying

    5 50
    5 3
    1 1
    10 4
    7 2
    60 1

    8

    分析:这就是个简单贪心。

    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    #define range(i,a,b) for(int i=a;i<=b;++i)
    #define LL long long
    #define rerange(i,a,b) for(int i=a;i>=b;--i)
    #define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
    using namespace std;
    pair<LL,LL>fuck[100005];
    int n,m;
    LL ans;
    bool cmp(pair<LL,LL>a,pair<LL,LL>b){
        return a.first<b.first;
    }
    void init() {
        cin>>n>>m;
        range(i,1,n)cin>>fuck[i].first>>fuck[i].second;
        sort(fuck+1,fuck+1+n,cmp);
    }
    void solve(){
        range(i,1,n){
            LL MIN=min(m/fuck[i].first,fuck[i].second);
            ans+=MIN;m-=MIN*fuck[i].first;
        }
        cout<<ans<<endl;
    }
    int main() {
        init();
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    OC与AS3的观察者模式比较以及外部回调
    判断矩形重叠
    2010谷歌校园招聘笔试题
    2011谷歌校园招聘笔试题
    2012Google校园招聘笔试题
    2013谷歌校园招聘笔试题2
    2013谷歌校园招聘笔试题
    2012搜狗校园招聘笔试题
    2013搜狗校园招聘笔试题
    搜狐面试题
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9333579.html
Copyright © 2011-2022 走看看