zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 3

    609A - USB Flash Drives    20171108

    609B - The Best Gift    20171108

    前两题较为简单,故略过_(:з」∠)_

    609C - Load Balancing    20171108

    排一次序,求出mi的和之后就可以得出每个服务器的最终状态了,O(n)扫一遍求解即可

    我的代码在求解时只考虑了减小负载的数目之和,如果求的是变换量之和记得要除以2

    #include<bits/stdc++.h>
    using namespace std;
    int n,m[100001],s,ans;
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&m[i]),s+=m[i];sort(m+1,m+n+1);
        for(int i=n;i>=1;i--)ans+=max(m[i]-((i<=(n-s%n))?s/n:s/n+1),0);
        return printf("%d
    ",ans),0;
    }
    View Code

    609D - Gadgets for dollars and pounds    20180904

    预处理a[i],b[i]的前缀最小值及对应天数编号,之后二分答案并进行O(n)的检查是否可以满足条件即可。开始二分前应先判断是否有解,即对天数为n时进行判断。

    #include<bits/stdc++.h>
    using namespace std;
    #define N 200001
    #define LL long long
    struct rua{LL w;int d,id;}f[N];
    int n,m,k,s,a[N],b[N],t[N],c[N],ma[N],mb[N];
    priority_queue<LL,vector<LL>,greater<LL> >q;
    bool cmp(rua x,rua y){return x.w<y.w;}
    bool check(int x)
    {
        while(!q.empty())q.pop();
        for(int i=1;i<=m;i++)
          if(t[i]==1)q.push(1ll*c[i]*a[x]);
          else q.push(1ll*c[i]*b[x]);
        LL res=0;
        for(int i=1;i<=k;i++)
          {
          res+=q.top(),q.pop();
          if(res>1ll*s)return false;
          }
        return true;
    }
    void print(int d)
    {
        printf("%d
    ",d);
        for(int i=1;i<=m;i++)
          if(t[i]==1)f[i]={1ll*c[i]*a[d],ma[d],i};
          else f[i]={1ll*c[i]*b[d],mb[d],i};
        sort(f+1,f+m+1,cmp);
        for(int i=1;i<=k;i++)
          printf("%d %d
    ",f[i].id,f[i].d);
    }
    int main()
    {
        a[0]=b[0]=19260817;
        scanf("%d%d%d%d",&n,&m,&k,&s);
        for(int i=1;i<=n;i++)
          {
          scanf("%d",&a[i]);
          if(a[i]<a[i-1])ma[i]=i;
          else ma[i]=ma[i-1],a[i]=a[i-1];
          }
        for(int i=1;i<=n;i++)
          {
          scanf("%d",&b[i]);
          if(b[i]<b[i-1])mb[i]=i;
          else mb[i]=mb[i-1],b[i]=b[i-1];
          }
        for(int i=1;i<=m;i++)
          scanf("%d%d",&t[i],&c[i]);
        if(!check(n))return printf("-1
    "),0;
        int l=1,r=n;
        while(l<r)
          {
          int mid=l+r>>1;
          if(check(mid))r=mid;
          else l=mid+1;
          }
        return print(l),0;
    }
    View Code

    609E - Minimum spanning tree for each edge    20180905

    [Educational Round 3][Codeforces 609E. Minimum spanning tree for each edge]

    609F - Frogs and mosquitoes    20180910

    [Educational Round 3][Codeforces 609F. Frogs and mosquitoes]

  • 相关阅读:
    HDU 3537
    POJ 1175
    POJ 1021 人品题
    POJ 2068
    POJ 2608
    POJ 2960
    poj 1635
    ustc 1117
    ural 1468
    数字游戏
  • 原文地址:https://www.cnblogs.com/DeaphetS/p/9575243.html
Copyright © 2011-2022 走看看