Codeforces Round #326 (Div. 2)-Duff and Meat
题意:
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的更多相关文章
- Codeforces Round #326 (Div. 2)-Duff in Love
题意: 一个数x被定义为lovely number需要满足这样的条件:不存在一个数a(a>1),使得a的完全平方是x的因子(即x % a2 != 0). 给你一个数n,求出n的因子中为love ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 「日常训练」Duff in the Army (Codeforces Round #326 Div.2 E)
题意(CodeForces 588E) 给定一棵\(n\)个点的树,给定\(m\)个人(\(m\le n\))在哪个点上的信息,每个点可以有任意个人:然后给\(q\)个询问,每次问\(u\)到\(v\ ...
- 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 ...
- 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个 ...
随机推荐
- 关于图片加载非常爽的一个三方控件 fresco,一个三fresco
Hi EveryBody 今天来玩一个非常爽的控件 fresco 到底有多爽呢 接着看就知道了 首先 来看看fresco 是个神马东西 https://github.com/facebook/fre ...
- linux 跨IP拷贝命令 scp
原文:http://blog.csdn.net/mexican_jacky/article/details/52847094 scp -r ROOT/ tms2api@10.230.4.215:/Ja ...
- 【Linux系统】防暴力破解
在日志文件/var/log/secure 中可以看到涉及到安全方面的日志,可以查看是否有人尝试暴力破解及是否成功,对于肉鸡行为有一定帮助 思路基本上都是加强密码的复杂度,增加iptables配置黑名单 ...
- 反演dp经典
咋一看,至少要用3^n才能做到. 但. 首先定义: 可以发现只要求出a' b' 那么直接可以得出c' 那么如何求a'呢 //dp求a',其实就是分别用[0,n)来更新a' ; i < n; i+ ...
- mysql 截断
当id为int是,如果是10位数,可以插入,primary key不能重复插入,其默认值可以为NULL一个varchar字段的值如果长度设定为255,则如果其长度为256也可以插入,但已经被截取到了2 ...
- 能在CAD2004以下版本里面打开2007以上版本文件的外挂
下载地址:http://yunpan.cn/cjrxMKNubXQ5E 访问密码 1974 老何CAD工具安装办法:[推荐]先安装老何工具箱,然后用[扩展添加老何cad下拉菜单.bat]就完成老何下 ...
- Windows7隐藏字体
今天突然发现字体Times New Roman消失了,如下图所示: 图1.1 不仅仅Times New Roman,还有System.MS Sans Serif--这些熟悉的字体都消失了,不能选用了! ...
- linux笔记:linux帮助命令,man,help,whatis,apropos
命令名称:man功能:获得帮助信息命令所在路径:/usr/bin/man用法:man 命令或配置文件其他:会调用less来查看该命令或配置文件的帮助信息. 命令名称:whatis功能:获得命令的简短介 ...
- IIS提示Server Application Unavailable
浏览器访问网站,IIS提示Server Application Unavailable,我的解决方式是进入IIS管理界面,找到对应的站点,之后重启这个站点.
- Java线程(二):线程同步synchronized和volatile
上篇通过一个简单的例子说明了线程安全与不安全,在例子中不安全的情况下输出的结果恰好是逐个递增的(其实是巧合,多运行几次,会产生不同的输出结果),为什么会产生这样的结果呢,因为建立的Count对象是线程 ...