Codeforce 588A - Duff and Meat (贪心)】的更多相关文章

Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell mea…
A. Duff and Meat Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/problem/A Description Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly aikilo…
A. Duff and Meat time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exact…
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell mea…
题目大意:有一个人他有每天需要吃ai千克肉,并且当天肉的价格是pi,问N天后他至少需要花费多少钱买肉. 分析:注意一下,他是可以提前买好肉放着的. 代码如下: #include<iostream> #include<string.h> #include<stdio.h> #include<algorithm> #include<math.h> using namespace std; ; ; int main() { int N; while(s…
题意: Duff每天要吃ai千克肉,这天肉的价格为pi(这天可以买好多好多肉),现在给你一个数值n为Duff吃肉的天数,求出用最少的钱满足Duff的条件. 思路: 只要判断相邻两天中,今天的总花费 = ai*pi 与昨天的总花费(还有加上今天要吃的肉的重量)= (ai-1 + ai)*pi-1 . 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <fstream>…
题意: 商店准备用n天售货(每天的货物都是一样的),第i天会卖ki件货物,并且会有li个顾客来买. 如果货物没卖完, 那么每个顾客一定会买一件. 如果货物有剩, 不会保存到第二天. 现在给定一个f, 说明f天商店会双倍进货, 求哪几天选为f天商店售货最多. 第一个用例选第二第四天加倍, 第二个用例选第三天加倍. 分析: 一开始想了一个错误的贪心,以为只要求出min(货物*2,顾客)的值, 然后根据这个值来排序, 前f个取min(货物*2,顾客),后面的取min(货物,顾客)就能得出正确答案. 但…
题意 有一个人,想吃 $n$ 天肉,第 $i$ 天需要吃 $a[i]$ 块肉,第 $i$ 天超市肉价为每块 $b[i]$ 元,买来的肉可以留到后面吃,求这个人在每天都吃到肉的情况下花费的最小值. 题目标签:贪心 思路 一边输入一边计算,每次记录下最低价格,即 $mini=min(mini,b[i])$ 然后乘以每天所需要的肉的数量.即 $ans+=mini\times a[i]$ . 代码段: 比较容易实现 for(int i=0;i<n;i++) { cin>>a[i]>>…
题目 农夫约翰决定去做一个环游国家旅行,为了不让他的奶牛们感到孤单,于是他决定租一辆货车带领他的奶牛们一起去旅行.这辆货车的油箱最多可以承载G 个单位的油,同时为了简化问题,规定每一个单位的油可以行使一个单位的距离.约翰从起点出发到终点总共要经过D 个单位的距离.约翰知道自己很有可能要在中途的过程中加几次油.他将中途的N 个加油站(加油站看成是排成一条直线的)的位置都记录下来了.对于每一个加油站,他记录了这个加油站到起点的距离Xi,同时也记录了这个加油站的每个单位的油价Yi. 问题描述: 给定以…
C. Duff in the Army Recently Duff has been a soldier in the army. Malek is her commander. Their country, Andarz Gu has n cities (numbered from 1 to n) and n - 1 bidirectional roads. Each road connects two different cities. There exist a unique path b…