zoukankan      html  css  js  c++  java
  • UVA 11136 Hoax or what (multiset)

    题目大意:

    超时进行促销。把账单放入一个箱子里

    每次拿取数额最大的和最小的,给出 最大-最小  的钱。

    问n天总共要给出多少钱。


    思路分析:

    multiset 上直接进行模拟

    注意要使用long long 

    并且multiset的删除要用 迭代器。


    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <cstring>
    #include <set>
    #define maxn 111111
    using namespace std;
    
    multiset<int>tab;
    multiset<int>::iterator it;
    
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF && n)
        {
            tab.clear();
    
            long long ans=0;
            for(int i=0;i<n;i++)
            {
                int k;
                scanf("%d",&k);
                while(k--)
                {
                    int a;
                    scanf("%d",&a);
                    tab.insert(a);
                }
    
                if(tab.size()==0)continue;
                it=tab.begin();
                int ans1=(*it);
    
                it=((tab.end()));
                it--;
                int ans2=(*it);
    
                ans+=(ans2-ans1);
    
                tab.erase(it);
                if(tab.size()>0)tab.erase(tab.begin());
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
    


  • 相关阅读:
    HttpWebRequest后台读取网页类
    MD5加密方法
    Base64封装类
    3DES封装类
    C#操作XML类
    XML_Qt_资料
    XML_CPP_资料
    h.264_javascript_资料
    ffmpeg_资料_01
    QWebEngineView_简单例子_01
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/9941656.html
Copyright © 2011-2022 走看看