zoukankan      html  css  js  c++  java
  • Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1)题解

    Problem A

    就特判一下2和1,其他看一下奇偶就好了。

    Problem B

    看是否有一样的字母

    Problem C

    贪心贪不出来,要死了,哇哇大哭。结果还是个二分题,二分答案,然后贪心的判定就好了。

    Code

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=2e5+10;
    typedef long long ll;
    void check_max (int &a,int b) {a=max (a,b);}
    ll lim;
    int a[maxn],st[maxn];
    int n,temp[maxn];
    int p[maxn];
    
    bool check (int mid) {
      ll ans=0;
      memset (temp,0,sizeof (temp));
      for (int i=1;i<=mid;i++) temp[i]=st[i];
      sort (temp+1,temp+1+mid); reverse (temp+1,temp+mid+1);
      for (int i=1;i<=n;i++) {
        ans+=temp[i]*a[i];
        if (ans>=lim) return true;
      }
      return false;
    }
    
    int main () {
      int t;
      scanf ("%d",&t);
      while (t--) {
        scanf ("%d",&n);
        memset (a,0,sizeof (a));
        for (int i=1;i<=n;i++) scanf ("%d",&a[i]),a[i]/=100;
        sort (a+1,a+n+1);
        reverse (a+1,a+n+1);
        int pos,gap;
        memset (st,0,sizeof (st));
        scanf ("%d%d",&gap,&pos);
        for (int i=pos;i<=n;i+=pos) st[i]+=gap;
        scanf ("%d%d",&gap,&pos);
        for (int i=pos;i<=n;i+=pos) st[i]+=gap;
        scanf ("%lld",&lim);
        ll now=0;
        memset (p,0,sizeof (p));
        for (int i=1;i<=n;i++) p[i]=st[i];
        sort (p+1,p+n+1); reverse (p+1,p+n+1);
        for (int i=1;i<=n;i++) now+=p[i]*a[i];
        if (now<lim) printf ("-1
    ");
        else {
          int l=0,r=n;
          while (l<r) {
            int mid=(l+r)>>1;
            if(check (mid)) r=mid;
            else l=mid+1;
          }
          printf ("%d
    ",l);
        }
      }
      return 0;
    }
    
  • 相关阅读:
    MQTT TLS 加密传输
    python多进程并发redis
    各种消息队列的特点
    mqtt异步publish方法
    Numpy API Analysis
    Karma install steps for unit test of Angular JS app
    reinstall bower command
    Simulate getter in JavaScript by valueOf and toString method
    How to: Raise and Consume Events
    获取对象的类型信息 (JavaScript)
  • 原文地址:https://www.cnblogs.com/hhlya/p/13926300.html
Copyright © 2011-2022 走看看