随笔——CodeForces 588A Description

题目的意思是给你多组清单,每组包含所需食物的数量,和当天食物的单价,可以囤积食物。求花最少的钱完成清单。

解决这道题目的策略是从头到尾扫描一遍这些清单,再遇到更便宜的价格前都用之前最便宜的价格买食物,再更新当前最便宜的价格,以此类推下去。

数组a[ ]代表各天地食物需求

数组b[ ]代表各天地食物单价

变量cheap代表当前最便宜的单价是哪天

#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

#define  MAX(x,y) (((x)>(y)) ? (x) : (y))
#define  MIN(x,y) (((x) < (y)) ? (x) : (y))
#define ABS(x) ((x)>0?(x):-(x))

const int inf = 0x7fffffff;

const int N=100000+10;
int a[N];
int b[N];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        scanf("%d%d",a+i,b+i);
    }
    int cheap=0;
    int cnt=a[0];
    long long ans=0;
    for(int i=1; i<n; i++){
        if(b[i] < b[cheap] ){
            ans += b[cheap]*cnt;
            cnt=a[i];
            cheap=i;
        }
        else{
            cnt += a[i];
        }
//        cout<<"ans= "<<ans<<endl;
    }
    ans += b[cheap]*cnt;
    cout<<ans<<endl;
    return 0;
}
时间: 2024-11-06 07:39:09

随笔——CodeForces 588A Description的相关文章

CodeForces 588A

题意:Duff为了保持n天开心第i天能保持开心需要吃ai千克的肉,每天的肉价为pi kg/dollars,每天可以买任意多的肉,输出Duffn天开心的最小花费. 题解:第i天的最小花费为ai*min(p1,p2.....pi):将每天的最小花费累加即为解 #include <iostream> using namespace std; int main() { int n; while(cin>>n) { int a,p,MIN; MIN=0x0f0f0f0f; int sum=0

CodeForces 171F(千古神题。。)

 D - 乐 Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 171F Description qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf. Input j

CodeForces 433C Ryouko&#39;s Memory Note-暴力

Ryouko's Memory Note Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 433C Description Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in

codeforces 589 D - Boulevard

D - Boulevard Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589D Description Welcoming autumn evening is the best for walking along the boulevard and n people decided to do so. The bou

Codeforces 130A - Testing Pants for Sadness(解题报告)

Testing Pants for SadnessCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 103A Description The average miner Vaganych took refresher courses. As soo

Codeforces Round #203 (Div. 2)B Resort

Resort Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 350B Description Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip b

CodeForces 706C dp

C - Hard problem Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 706C Description Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he as

CodeForces 1A Theatre Square

A - Theatre Square Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 1A Description Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the

CodeForces 300C 最短路

A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 300C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal