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 头奶牛(方便起见,编号为 ...
随机推荐
- java操作elasticsearch实现基本的增删改查操作
一.在进行java操作elasticsearch之前,请确认好集群的名称及对应的ES节点ip和端口 1.查看ES的集群名称 #进入elasticsearch.yml配置文件/opt/elasticse ...
- PyQt5--QComboBox
# -*- coding:utf-8 -*- ''' Created on Sep 20, 2018 @author: SaShuangYiBing Comment: ''' import sys f ...
- Kafka设计原理
一.入门 1.简介 Apache Kafka是一个分布式消息发布订阅系统.它最初由LinkedIn公司基于独特的设计实现为一个分布式的提交日志系统( a distributed commit log) ...
- GUI_键盘事件
import java.awt.Button; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.TextField ...
- CF895C: Square Subsets && 【BZOJ2844】albus就是要第一个出场
CF895C: Square Subsets && [BZOJ2844]albus就是要第一个出场 这两道题很类似,都是线性基的计数问题,解题的核心思想也一样. CF895C Squa ...
- 1192:放苹果(dp + 搜索)
这道题先用搜索写的,因为我需要先打表来寻找规律. 因为数据量小所以收搜也会过 #include<iostream> #include<cstdio> #include<c ...
- day14 Python集合
定义:由不同元素组成的集合,集合是一组无序排列的可hash值,可以作为字典的key 1.不同元素.2.无序.3.集合中元素必须是不可变类型(数字,字符串,元祖) 特性:集合的目的是将不同的值存放在一起 ...
- java-深克隆和浅克隆
文章参考 https://www.cnblogs.com/acode/p/6306887.html 一.前提 1.使用clone()方法的类,必须实现Cloneable接口, 否则调用clone()方 ...
- Unicode(UTF-8, UTF-16)令人混淆的概念(转)
文章转自http://www.cnblogs.com/kingcat/archive/2012/10/16/2726334.html (http://swiftlet.net/archives/cat ...
- maven中的mirrors
文章转自http://blog.csdn.net/technologyboy/article/details/17143641 简单点来说,repository就是个仓库.maven里有两种仓库,本地 ...