题意:

  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. iOS--获取输入字符的第一个字母(汉字则获取拼音的第一个字母)

    - (NSString *)firstCharactor:(NSString *)aString { //转成了可变字符串 NSMutableString *str = [NSMutableStrin ...

  2. git命令之git rebase 的用法

    rebase 假设你现在基于远程分支"origin",创建一个叫"mywork"的分支. $ git checkout -b mywork origin 现在我 ...

  3. HTML5地理位置概述和地理位置对象的详解

    一.地理位置 经度  :   南北极的连接线 纬度  :   东西连接的线   二.位置信息从何而来 IP地址 GPS全球定位系统 Wi-Fi无线网络 基站         三.地理位置对象(navi ...

  4. Canu FAQ常见问题

    链接:Canu FAQ Q: What resources does Canu require for a bacterial genome assembly(细菌基因组组装)?   A mammal ...

  5. SQL中SUBSTRING函数的用法

    功能:返回字符.二进制.文本或图像表达式的一部分 语法:SUBSTRING ( expression, start, length ) SQL 中的 substring 函数是用来抓出一个栏位资料中的 ...

  6. Linux源码安装mysql步骤

    创建文件夹: mkdir  /usr/local/webserver 安装必要依赖包      yum -y install gcc gcc-c++ make ncurses-devel安装cmake ...

  7. jq slideUp slideDown

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. fork&exec

    进程是系统进行资源分配和调度的基本单位,包括代码.数据和PCB进程控制块等资源. fork函数通过系统调用创建一个与原进程相同的子进程. 在调用进程(父进程)中返回一次,返回子进程ID:在子进程返回0 ...

  9. GetMemory

    在函数中动态申请内存(虚拟内存,堆),利用指针返回值指向申请的内存.

  10. Visual Studio 2010 类模板的修改

    第一步:找到类文件模板路径 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\C ...