【985系列】985的买饮料难题
来源:互联网 发布:事业单位养老金知乎 编辑:程序博客网 时间:2024/06/03 01:44
Problem E: 985的买饮料难题
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 240 Solved: 128
SubmitStatusWeb Board
Description
天气太热了,985制定了对未来的规划即第i天喝a[i]瓶饮料。为了节约开支,他打听到了第i天每瓶饮料的价格p[i]。
为了不让自己的规划落空,他想知道这n天他至少要花多少钱。
精明的985可以选择在任意一天买数目不限的饮料,而且他有一个神奇的冰箱,可以将提前购买的饮料保存下来(至少在这n天里是可以饮用的)。
Input
第一行输入一个整数t,代表有t组测试数据。
每组数据第一行输入一个整数n代表规划的总天数,接下来有n行,每行输入两个整数a[],p[]分别代表上面提到的信息。
注:1 <= t <= 30,1 <= n <= 1000,1 <= a[],p[] <= 100。
Output
输出一个整数代表最后的结果。
Sample Input
2225 5694 17539 2195 8973 909 5585 32
Sample Output
29986321
HINT
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int N = 1000+10; int a[N],p[N],vis[N]; int main() { int T; scanf("%d",&T); while(T--) { int n,sum=0; scanf("%d",&n); for(int l=1; l<=n; l++) scanf("%d%d",&a[l],&p[l]); int flag=1,cnt; cnt=p[1]; vis[0]=1; for(int l=2; l<=n; l++) { if(p[l]<cnt) { cnt=p[l]; vis[flag]=l; flag++; } } vis[flag]=n+1; int t; for(int l=0; l<flag; l++) { t=vis[l]; for(int j=t; j<vis[l+1]; j++) { sum=sum+p[t]*a[j]; } } printf("%d\n",sum); } return 0; } /************************************************************** Problem: 1896 Language: C++ Result: Accepted Time:7 ms Memory:884 kb ****************************************************************/
0 0
- 【985系列】985的买饮料难题
- 985的买饮料难题
- 985的买饮料难题
- 1896: 985的买饮料难题
- 【zzulioj 1896 985的买饮料难题 】
- zzulioj 1896 985的买饮料难题
- ZZULIOJ-1896-985的买饮料难题(水题)
- zzulioj1896 985的买饮料难题(数学)
- ZZULI OJ 1896: 985的买饮料难题
- 【郑轻】[1896]985的买饮料难题
- 【zzuliOJ】1896 - 985的买饮料难题(贪心)
- 【ZZULI】-1896-985的买饮料难题(思维)
- 【多校训练】ZZULIOJ 1896 985的买饮料难题
- 【HPU 1019 】985的买饮料难题 (dp)
- 【hpu oj 1019 985的买饮料难题 [数学、DP]】
- 买饮料难题
- 买饮料难题
- 买饮料
- 03、canvas标签之绘制矩形
- Java中信号量Semaphore的简单使用
- 线性结构--->线性表实现
- 访问php页面报一下错误的解决办法
- 【20】Valid Parentheses
- 【985系列】985的买饮料难题
- Neerc2005 POJ2794 Double Patience
- MongoDB数据操作
- BOM
- 原型图工具功能比拼1
- poj 2796
- Modular Programming with JavaScript-Packt Publishing 2016(读书笔记)
- 二分图最大匹配模板
- java工程_web.xml配置session有效期