zoukankan      html  css  js  c++  java
  • 繁华模拟赛day8 科技树

    /*
    贪心,很明显是越容易升级的越先升级
    */
    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int maxn = 100050;
    int n,k,t,a[maxn],lv[maxn],ans;
    int read(){
        char ch=getchar();
        int x=0,f=1;
        while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();};
        while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();};
        return x*f;
    }
    bool cmp(int a,int b){
        return (a % 10) > (b % 10);
    }
    int main(){
        freopen("science.in","r",stdin);
        freopen("science.out","w",stdout);
        n = read();
        k = read();
        for(int i = 1;i <= n;i++) a[i] = read();
        sort(a+1,a+1+n,cmp);
        for(int i = 1;i <= n;i++){
            lv[i] = a[i] / 10;
            t = 10 - (a[i] % 10);
            if(k >= t && lv[i] <= 9){
                k -= t;
                lv[i]++;
                a[i] = 0;
            }
        }
        for(int i = 1;i <= n;i++){
            if(lv[i] <= 9){
                t = min(10-lv[i],k/10);
                lv[i] += t;
                k -= t*10;
            }
            ans += lv[i];
        }
        cout<<ans;
        return 0;
    } 
  • 相关阅读:
    Array.sort源码
    单例模式
    nio理解
    xoa中范型的应用
    mybatis 一对多映射 xml
    zookeeper
    java final
    spring controller里面返回JSONObject与返回String的不同
    synchronized的可重入性
    nio select poll epoll
  • 原文地址:https://www.cnblogs.com/hyfer/p/5982017.html
Copyright © 2011-2022 走看看