zoukankan      html  css  js  c++  java
  • 【codeforces 767E】Change-free

    【题目链接】:http://codeforces.com/problemset/problem/767/E

    【题意】

    你有m个1元硬币和无限张100元纸币;
    你在第i天,需要花费ci元;
    同时在第i天,收银员有一个不高兴程度wi;
    然后如果它要找零x张纸币y枚硬币的话,它的不高兴值会为wi*(x+y)
    找的零钱会回到你的口袋里;
    问你n天的,总的最小不高兴值;

    【题解】

    整百的部分,直接用纸币填就好了;
    则直接对ci%100考虑;
    即要直接用硬币填满ci%100,或者是先给一张100,然后让他找你钱;
    如果m>=ci;
    则直接用硬币填它,这样不会有不满意;
    m-=ci;
    然后记录如果给一张纸币的话,会增加多少不满意度;
    放入优先队列中;
    如果m< ci;
    则考虑修改之前的贪心;
    如果优先队列的第一个元素比w[i]*(100-a[i])小;
    则把之前的那一个修改成用一张纸币填;
    然后那时因为已经减去ci了,所以修改的话,硬币数直接加上100;
    而这100可以保证够把当前的ci用硬币填
    则,用硬币填就是了;
    如果不满足优先队列的第一个元素比w[i]*(100-a[i])小;
    则这个用一张纸币填;

    【Number Of WA

    0

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0),cin.tie(0)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 1e5+100;
    
    struct abc
    {
        LL val,id;
        friend bool operator < (abc a,abc b)
        {
            if (a.val!=b.val)
                return a.val>b.val;
            else
                return a.id<b.id;
        }
    };
    
    LL n,m;
    LL ans1[N],ans2[N],a[N],w[N];
    priority_queue<abc> xiao;
    
    int main()
    {
        //Open();
        Close();//scanf,puts,printf not use
        //init??????
        cin >> n >> m;
        rep1(i,1,n)
        {
            cin >> a[i];
            ans1[i]=a[i]/100;
            a[i]%=100;
        }
        rep1(i,1,n)
            cin >> w[i];
        LL ans = 0;
        rep1(i,1,n)
        if (a[i])
        {
            if (m>=a[i])
            {
                m-=a[i];
                xiao.push(abc{w[i]*(100-a[i]),i});
                continue;
            }
            //m<a[i]
    
            if (xiao.empty())
            {
                m+=100-a[i];
                ans+=w[i]*(100-a[i]);
                ans2[i] = 1;
                continue;
            }
    
            if (xiao.top().val<w[i]*(100-a[i]))
            {
                ans2[xiao.top().id] = 1;
                ans+=xiao.top().val;
                xiao.pop();
                m+=100;
                m-=a[i];
                xiao.push(abc{w[i]*(100-a[i]),i});
            }
            else
            {
                m+=100-a[i];
                ans+=w[i]*(100-a[i]);
                ans2[i] = 1;
            }
        }
        cout << ans << endl;
        rep1(i,1,n)
            if (ans2[i])
                cout << ans1[i]+1 <<' '<<0<<endl;
            else
                cout << ans1[i] <<' '<<a[i]<<endl;
        return 0;
    }
    
  • 相关阅读:
    240. Search a 2D Matrix II
    436. Find Right Interval
    378. Kth Smallest Element in a Sorted Matrix
    278. First Bad Version
    374. Guess Number Higher or Lower
    207. Course Schedule
    Java enum的用法详解
    Android中RelativeLayout各个属性 android:layout_alignParentLeft=”true”找不到有时候
    android:layout_gravity和android:gravity的区别
    Android 相对布局 扩展
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626305.html
Copyright © 2011-2022 走看看