【Codeforces Round 326 (Div 2)A】【贪心】Duff and Meat 屯肉前溯花费最低
来源:互联网 发布:c:foreach标签循环数组 编辑:程序博客网 时间:2024/06/10 14:41
#include<stdio.h>#include<string.h>#include<ctype.h>#include<math.h>#include<iostream>#include<string>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}const int N=0,M=0,Z=1e9+7,ms63=1061109567;int casenum,casei;int main(){int n;while(~scanf("%d",&n)){int P=1e9;int ans=0;for(int i=1;i<=n;i++){int num,pri;scanf("%d%d",&num,&pri);gmin(P,pri);ans+=num*P;}printf("%d\n",ans);}return 0;}/*【题意】有n(1e5)天时间,对于第i天,我们要消耗num[i]单位的食物,这天如果选择买食物,1单位食物的单价为pri[i],每天买的食物数量都没有上限,可以囤积到最后。问你满足这n天的食物需求,最少需要花多少钱。【类型】贪心【分析】首先,我们发现,如果某天买食物的单价比之后的都低,那我们肯定以这个价买。这样从前向后有一个阶段性的延展,思考起来和实现起来都有些困难。于是,我们可以变化一下,做从后向前的思维。对于每天食用的食物,价格肯定是在它之前的最低价买的。于是更新一个前缀最低价,这道题就做完了。*/
1 0
- 【Codeforces Round 326 (Div 2)A】【贪心】Duff and Meat 屯肉前溯花费最低
- Codeforces Round #326 (Div. 2) A. Duff and Meat
- Codeforces Round #326 (Div. 2) 588 A. Duff and Meat
- Codeforces Round #326 (Div. 2) A. Duff and Meat
- Codeforces Round #326 (Div. 2) A. Duff and Meat
- Codeforces#326-A - Duff and Meat-贪心
- Codeforces Round #326 A. Duff and Meat
- CodeForces 588A Duff and Meat 贪心
- Codeforces 588 A. Duff and Meat
- CodeForces-588A Duff and Meat
- Codeforces 558 A Duff and Meat
- codeforces 588 A Duff and Meat
- Codeforces 588A Duff and Meat 【dp】
- Codeforces 588.A Duff and Meat
- CodeForces 588A. Duff and Meat
- Codeforces Round #326 (Div. 1)A. Duff and Weight Lifting
- Codeforces Round #326 (Div. 1)-A. Duff and Weight Lifting
- A. Duff and Meat
- cordova插件中exec()总是返回error的原因
- Xcode7 真机调试 遇到 no identity found 如何解决
- 跨站攻击的解决方法
- Android中的“再按一次返回键退出程序”实现
- spring和hibernate整合开发web项目的创建及所需的jar包的添加
- 【Codeforces Round 326 (Div 2)A】【贪心】Duff and Meat 屯肉前溯花费最低
- python常见模块命令(os/sys/platform)
- Android Call requires API level 11 (current min is 8)的解决方案
- ubuntu清理系统垃圾与备份,已经常用命令
- 10.1 图标、鼠标指针、字符串和自定义资源
- ALV GRID 使用过滤器(FILTER)的方法
- JDBC创建步骤
- bmp
- HDMI管脚定义