C. Party Lemonade
链接
[http://codeforces.com/group/1EzrFFyOc0/contest/913/problem/C]
分析
看代码,巧妙的贪心
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,l;
ll c[40];
int i;
//freopen("in.txt","r",stdin);
while(cin>>n>>l){
ll ans=0;
for(i=0;i<n;i++)
cin>>c[i];
for(i=1;i<n;i++)
if(2*c[i-1]<c[i]) c[i]=2*c[i-1];//选择性价比最高
//下面很关键,你可以把一个十进制数换成二进制数,因为题目刚好type i has volume 2^i-1 liters
for(i=0;i<n;i++){
if(ans>c[i]) ans=c[i];//如果已经买的价格超过了现在的价格而现在的容量一定大于已经买的
//你多买了而且价格还底何乐而不为呢
if(l&1) ans+=c[i];//当二进制位为1的时候就买
l/=2;//相当于十进制化为二进制的过程
}
l*=2;//因为上面只枚举到第n种类型,可能没买完要买的而且我们每个for都除2所以要乘以2
ans+=l*c[n-1];//选最后的类型,因为剩下的是l*2^n-1升
cout<<ans<<endl;
}
return 0;
}
C. Party Lemonade的更多相关文章
- [LeetCode] Lemonade Change 买柠檬找零
At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and ...
- [Swift]LeetCode860. 柠檬水找零 | Lemonade Change
At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and ...
- LeetCode-860. Lemonade Change
At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and ...
- [LeetCode] 860. Lemonade Change_Easy tag: Greedy
At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and ...
- [LeetCode&Python] Problem 860. Lemonade Change
At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and ...
- LeetCode – Lemonade Change
At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and ...
- Codeforces 913C - Party Lemonade
913C - Party Lemonade 思路:对于第i个话费cost[i],取min(cost[i],2*cost[i-1]),从前往后更新,这样就可以保证第n个的话费的性价比最高,那么从最高位开 ...
- 【CodeForces】913 C. Party Lemonade
[题目]C. Party Lemonade [题意]给定n个物品,第i个物品重量为2^(i-1)价值为ci,每个物品可以无限取,求取总重量>=L的最小代价.1<=30<=n,1< ...
- Lemonade Trade
4990: Lemonade Trade 时间限制: 1 Sec 内存限制: 128 MB Special Judge提交: 88 解决: 17[提交][状态][讨论版][命题人:admin] ...
- 洛谷 P4379 [USACO18OPEN]Lemonade Line
P4379 [USACO18OPEN]Lemonade Line 题目描述 这是农场上一个炎热的夏日,Farmer John要给他的 NN 头奶牛发柠檬汽水了!所有的 NN 头奶牛(方便起见,编号为 ...
随机推荐
- VSCode + PYQT5 + QtDesigner 环境搭建和测试
目的:编写Python桌面应用程序. 备注:也可以选择VS2017+QtDesigner ,但更喜欢VSCode 第1步:安装PyQt5和PyQt5-tools pip3 install -i htt ...
- 【PAT】B1064 朋友数(20 分)
以前写的,逻辑不好,过后再改 #include<stdio.h> #include<algorithm> #include<math.h> using namesp ...
- 【2017下集美大学软工1412班_助教博客】团队作业9——事后分析(Beta版本)成绩公示
作业要求 团队作业9 团队评分结果 编号 Total 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2 ...
- C#的list和arry相互转化
,从System.String[]转到List<System.String> System.String[] str={"str","string" ...
- Ngnix中的fastcgi參数性能优化和解释
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/luozhonghua2014/article/details/37737823 优化性能參数设置,在 ...
- 莫比乌斯函数 51nod-1240(合数分解试除法)
就是输出n时,莫比乌斯函数的值.直接将n唯一分解即可. 思路:筛出105以内的素数,因为109开方,105就差不多.当一个大数还没有被1000个素数分解,那么这个数基本上可以认为是素数(为合数为小概率 ...
- kafka TimeoutException 超时问题解决
1.报错:: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.NotLeaderForPartition ...
- go标准库的学习-net
参考:https://studygolang.com/pkgdoc 导入方式: import "net" net包提供了可移植的网络I/O接口,包括TCP/IP.UDP.域名解析和 ...
- MetaMask/safe-event-emitter
https://github.com/MetaMask/safe-event-emitter safe-event-emitter An EventEmitter that isolates the ...
- 一加将在欧洲推出第一款商用 5G 手机
远在太平洋中部的夏威夷群岛,高通举办了骁龙峰会. 峰会的惯例,各行业的合作伙伴都被邀请上台演讲.中国企业里,去年来的是小米雷军,而今年刚开场,一加手机 CEO 刘作虎就现身了. 与以往一样,张老板身着 ...