题意:

  Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件。

思路:

  只要判断相邻两天中,今天的总花费 = ai*pi 与昨天的总花费(还有加上今天要吃的肉的重量)= (ai-1 + ai)*pi-1 。

代码如下:

  

  

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010 int main()
{
int n, sum, tot;
while(scanf("%d", &n)==&&n)
{
tot = ;
int i;
int a, p, x, y;
for(i = ; i < n; i++ )
{
sum = ;
scanf("%d%d", &a, &p);
if(i == )
{
sum += a*p;
x = a;
y = p;
}
else
{
if(a*p + x*y > (x+a)*y)
{
sum += a*y;
}
else
{
sum += a*p;
x = a;
y = p;
}
}
tot += sum;
}
printf("%d\n", tot);
} return ;
}

第二种写法:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 100010
#define MAXM 1000010 int a[MAXN], p[MAXN], dp[MAXN];
int main()
{
int n;
int ans;
while(scanf("%d", &n)==)
{
int i;
ans = ;
for(i = ; i <= n; i++ )
{
scanf("%d%d", &a[i], &p[i]);
if(i == )
dp[i] = p[i];
else
dp[i] = min(dp[i-], p[i]);
}
for(i = ; i <= n; i++ )
ans += a[i]*dp[i];
printf("%d\n", ans);
} return ;
}

Codeforces Round #326 (Div. 2)-Duff and Meat的更多相关文章

  1. Codeforces Round #326 (Div. 2)-Duff in Love

    题意: 一个数x被定义为lovely number需要满足这样的条件:不存在一个数a(a>1),使得a的完全平方是x的因子(即x % a2  != 0). 给你一个数n,求出n的因子中为love ...

  2. Codeforces Round #326 (Div. 2) A. Duff and Meat 水题

    A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...

  3. Codeforces Round #326 (Div. 2) D. Duff in Beach dp

    D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...

  4. Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题

    C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  5. Codeforces Round #326 (Div. 2) B. Duff in Love 分解质因数

    B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/proble ...

  6. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...

  7. 「日常训练」Duff in the Army (Codeforces Round #326 Div.2 E)

    题意(CodeForces 588E) 给定一棵\(n\)个点的树,给定\(m\)个人(\(m\le n\))在哪个点上的信息,每个点可以有任意个人:然后给\(q\)个询问,每次问\(u\)到\(v\ ...

  8. Codeforces Round #326 (Div. 2) B Duff in Love 简单数论 姿势涨

    B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces Round #326 (Div. 1) - C. Duff in the Army 树上倍增算法

    题意:一个n个点的数, m个人住在其中的某些点上, 每个人的标号1-m, 询问u-v 路径上标号前a个人,并输出标号,a < 10. 作法, 利用倍增, ID[j][i] 表示i到i的第2^j个 ...

随机推荐

  1. myeclipse黑色主题怎么还原

    删除workspace-->.metadata-->.plugins-->org.eclipse.core.runtime

  2. windows多线程框架

    #include <iostream> #include <windows.h> using namespace std; HANDLE hMutex; //public : ...

  3. 决策树原理、Scikit-learn实现及其在生物信息中的应用

    之前转过一篇文章:2016年GitHub排名前20的Python机器学习开源项目(转),说明现在已经有了很多很好的机器学习的包,我们不必从底层开始实现,只要懂点算法.会看文档,一般人也能玩好机器学习. ...

  4. Linux安装多个Python版本

    服务器上的Python版本太老了,需要安装一个新的Python版本,才能跑我的代码.因为环境的需要,但是又不能卸载老的版本,所以安装一个新的,使用软链来进行升级. 使用系统自带的yum,apt-get ...

  5. HDELETE

    use HDELETE to migration file deletion is good a choice. sample: //STEP0010 EXEC PGM=IKJEFT01 //SYSO ...

  6. JavaScript window

    window -- window对象是BOM中所有对象的核心 window,中文"窗口" window对象除了是BOM中所有对象的父对象外,还包含一些窗口控制函数 全局的windo ...

  7. Java集合框架:HashMap

    转载: Java集合框架:HashMap Java集合框架概述   Java集合框架无论是在工作.学习.面试中都会经常涉及到,相信各位也并不陌生,其强大也不用多说,博主最近翻阅java集合框架的源码以 ...

  8. spring来了-06-事务控制

    概述 编程式事务控制 自己手动控制事务,就叫做编程式事务控制. Jdbc代码: Conn.setAutoCommite(false);  // 设置手动控制事务 Hibernate代码: Sessio ...

  9. Windows下Git的安装及配置

    Git的BASH Git的为Windows提供了用于命令行运行的一个仿真BASH的Git.习惯LINUX和UNIX环境的你,可以在该BASH环境中输入“git”命令来完成各种版本控制的操作. 简介 G ...

  10. 【MYSQL】update/delete/select语句中的子查询

    update或delete语句里含有子查询时,子查询里的表不能在update或是delete语句中,如含有运行时会报错:但select语句里含有子查询时,子查询里的表可以在select语句中. 如:把 ...