首页 > 其他 > 详细

bzoj 2430: [Poi2003]Chocolate 贪心

时间:2019-10-28 17:14:34      阅读:85      评论:0      收藏:0      [点我收藏+]

发现每一次切割都会使另一方向所有切割次数++.
而每一刀的代价就是 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\n",ans);   
    return 0;  
}

bzoj 2430: [Poi2003]Chocolate 贪心

原文:https://www.cnblogs.com/guangheli/p/11753292.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!