您的位置:首页 > 其它

## Hello 2018 C. Party Lemonade ##

2018-01-23 11:59 393 查看
## Hello 2018 C. Party Lemonade ##

http://codeforces.com/contest/913/problem/C

算法:贪心

思路:

求出每个2^(i-1)体积对应下的最小cost(利用倍数关系遍历一遍)

从最大体积的瓶子开始买,因为瓶子不可分割,可用 (L+v-1)/v 表示:当前只购买体积v并确保填满L的,所需瓶数(多买一点可能更便宜)L为剩余所需体积数

#include <bits/stdc++.h>
#define pi acos(-1)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL ll_INF = 0x3f3f3f3f3f3f3f3f;//4e18 ~= 2^62
const int N =1000 + 10;
const LL mod = 1e9+7;////////注意mod 为longlong
LL c
;

int main()
{
int n, l;
scanf("%d%d" ,&n, &l);
for(int i=1; i<=n; i++){
scanf("%d", &c[i]);
}
for(int i=2; i<=n; i++){
c[i] = min(c[i]*1LL, 2LL*c[i-1]);
}
LL ans=ll_INF, anss=0;
for(int i=n; i>=1; i--){
LL v = 1LL<<i-1;
ans = min(ans, anss+(l+v-1LL)/v*c[i]);
anss += l/v*c[i];
l-=l/v*v;
}
printf("%I64d\n", ans);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  贪心