HDU 2018CCPC 网络赛 整理

1001 原题链接 https://blog.csdn.net/qq_28954601/article/details/78146932
本题链接:
用pair的原因是为了统计操作的次数。

#include<bits/stdc++.h>
using namespace std;
multiset<pair<long long ,int> >s;
int main()
{

    int T;
    scanf("%d",&T);
    while(T--)
    {
        s.clear();
      int n;
      scanf("%d",&n);
      long long  ans =0,cnt = 0;
      for(int i=1;i<=n;i++)
      {
          long long  x;
          scanf("%lld",&x);
          if(s.empty()||s.begin()->first>=x)
          {
               s.insert(make_pair(x,1));
          }
          else
          {
              pair<long long ,int>pr = *s.begin();
              ans+=x-pr.first;
              cnt+=pr.second*2;
              s.erase(s.begin());
              s.insert(make_pair(x,0));
              s.insert(make_pair(x,1));
          }
      }
      printf("%lld %lld\n",ans,cnt);
      //cout<<ans<<" "<<cnt<<endl;

    }
    return 0;
}

牛客网 第二场1004弱化版:
题意改为仓库最多只能存储一个货物、
直接统计上升序列的个数,类似于最大子段和。

#include<bits/stdc++.h>
#define ll long long
#define M 100005
using namespace std;
ll a[M];
int t,n;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        ll A=0,B=0;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int i=1;i<=n-1;i++){
            A+=max((int)(a[i+1]-a[i]),0);
        }
        int cnt=1;
        for(int i=2;i<=n;i++){
            if(a[i]>a[i-1])cnt++;
            else if(a[i]<a[i-1]){
                if(cnt>=2)B+=2;
                cnt=1;
            }
        }
        if(cnt>=2)B+=2;
        cout<<A<<" "<<B<<endl;
    }
}

1011 树状数组|线段树 二维偏序

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值