poj 2393 Yogurt factory
来源:互联网 发布:mac怎么打开多个终端 编辑:程序博客网 时间:2024/04/30 17:29
好久没做贪心的题了,找到简单的练练手,居然wrong 了一次,。。。。。
1.题意:一公司生产酸奶,已知生产一单位酸奶的价钱c[i];生产的总量y[i];每单位的酸奶存储费用是S,求接下来要生产N周的最低价;
2.思路:比较当前这周的单价与上周的单价加上储存费的高低,如果这周单价低,则选择这周的单价c[i]*y[i];否则,(c[i-1]+S)*y[i];
3.难点:注意数值较大,Note that the total might be too large for a 32-bit integer,int型不行,long居然也wrong 了;
正确:long long
注:定义是long至少不小于int,long long至少不小于long.在32位机器中,一般long和int同,为32,long long为64
代码:
#include<stdio.h>int c[10005],y[10005];int main(){ int N,S; long long sum=0; scanf("%d%d",&N,&S); for(int i=0;i<N;i++) { scanf("%d%d",&c[i],&y[i]); } sum=c[0]*y[0]; for(int i=1;i<N;i++) { if(c[i-1]+S>c[i]) sum+=c[i]*y[i]; else sum+=(c[i-1]+S)*y[i]; } printf("%lld\n",sum); return 0;}
- poj 2393 Yogurt factory
- POJ-2393-Yogurt factory
- poj 2393 yogurt factory
- poj 2393 Yogurt factory
- POJ-2393-Yogurt factory
- POJ 2393 Yogurt factory
- POJ 2393【Yogurt factory】
- POJ 2393 Yogurt factory
- POJ 2393 Yogurt factory
- poj 2393 - Yogurt factory
- POJ 2393 Yogurt factory
- POJ 2393 Yogurt Factory
- poj 2393 Yogurt factory
- poj 2393 Yogurt factory
- POJ 2393 Yogurt factory
- poj 2393 Yogurt factory
- poj 2393 Yogurt factory
- poj-2393-Yogurt Factory
- 少年、该醒醒了、
- Hibernate点滴
- Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead.报错!
- BlackBerry 9850 应用:Google地图
- JAVA字符串转日期或日期转字符串
- poj 2393 Yogurt factory
- 图像处理(二)直方图均衡化
- 日历时间加减法
- Hibernate分页查询
- MOS管开关电路设计知识
- 二叉树遍历:递归方法与非递归方法——递归程序修改为非递归的方法
- 系统程序设计学习笔记
- UbuntuServer搭建Git服务器之SSH基本用法(一)
- 移动mysql数据文件目录(datadir)以及selinux的一些经验