zoukankan      html  css  js  c++  java
  • bzoj 2430: [Poi2003]Chocolate 贪心

    发现每一次切割都会使另一方向所有切割次数++.
    而每一刀的代价就是 cost*切割次数,故贪心按照cost从大到小排序即可.

    #include <bits/stdc++.h> 
    #define N 200000    
    #define LL long long 
    using namespace std;  
    void setIO(string s) 
    {
        string in=s+".in"; 
        freopen(in.c_str(),"r",stdin);  
    }
    struct node 
    { 
        LL val;  
        int f;    
    }t[N];      
    bool cmp(node a,node b) { return a.val>b.val;  }
    int f[N];    
    int main() 
    { 
        // setIO("input");    
        int n,m,i,j;  
        scanf("%d%d",&n,&m); 
        --n,--m;   
        for(i=1;i<=n;++i) scanf("%lld",&t[i].val),t[i].f=0; 
        for(i=1;i<=m;++i) scanf("%lld",&t[n+i].val),t[n+i].f=1;   
        sort(t+1,t+1+n+m,cmp);        
        f[0]=f[1]=1;        
        LL ans=0ll;  
        for(i=1;i<=n+m;++i) 
        {
            ans+=t[i].val*f[t[i].f];   
            ++f[t[i].f^1];      
        }
        printf("%lld
    ",ans);   
        return 0;  
    }
    
  • 相关阅读:
    Idea中SpringBoot热部署搭建
    Redis 集群搭建
    centos7 vsftp搭建
    Centos 7 安装jdk
    Centos7 安装nginx
    Xshell 连接Linux
    python 的mysql 操作
    NIO/BIO
    java基础-3
    java基础-2
  • 原文地址:https://www.cnblogs.com/guangheli/p/11753292.html
Copyright © 2011-2022 走看看