An Invisible Hand(思维)

 

6480: An Invisible Hand

时间限制: 1 Sec  内存限制: 128 MB

题目描述

There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
Move: When at town i (i<N), move to town i+1.
Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for Ai yen (the currency of Japan) at town i (1≤i≤N), where Ai are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change Ai into another arbitrary non-negative integer Ai' for any town i, any number of times. The cost of performing this operation is |Ai−Ai'|. After performing this operation, different towns may have equal values of Ai.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.

Constraints
1≤N≤105
1≤Ai≤109 (1≤i≤N)
Ai are distinct.
2≤T≤109
In the initial state, Takahashi's expected profit is at least 1 yen.

输入

The input is given from Standard Input in the following format:
N T
A1 A2 … AN

输出

Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.

样例输入

3 2
100 50 200

样例输出

1

提示

In the initial state, Takahashi can achieve the maximum profit of 150 yen as follows:
1.Move from town 1 to town 2.
2.Buy one apple for 50 yen at town 2.
3.Move from town 2 to town 3.
4.Sell one apple for 200 yen at town 3.
If, for example, Aoki changes the price of an apple at town 2 from 50 yen to 51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost of performing this operation is 1, thus the answer is 1.
There are other ways to decrease Takahashi's expected profit, such as changing the price of an apple at town 3 from 200 yen to 199 yen.

 

有两个商人,互相看着不对付,总想找机会给对方下绊子。

现在,第一个商人要进行一个旅行,按顺序游历共n个城市,每个城市都有卖苹果的,都有个标价(各不相同),

现在商人希望在旅行结束后买卖苹果达到最大的利润(前面低价卖,后面高价卖),注意,这里商人

只能携带一个单位的苹果,然后另外一个商人不想让他获得最大利润,于是他会在某些城市改变苹果的价格,

让哪怕第一个商人损失1元(尽可能的大),求另一个商人所付出的最小代价(改变多少就花费多少)。

 

思路

        遍历每个城市,更新一个最小值和最大差值,每当出现一个峰顶的时候用峰顶减最小值得到差值,如果大于最大差值,那么更新最大差值,如果和最大差值相等那么计数君++,输出结果就行了

 

代码,emm oj关了,没了。。好了,现在找到了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 
    int n,t;
    scanf("%d%d",&n,&t);
 
    int cot = 1, minn , maxx = -10;
    int c,tc;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&c);
        if(i)
        {
            if(c>tc)
            {
                if(c-minn>maxx)
                    maxx=c-minn,cot = 1;
                else if(c-minn==maxx)
                    cot++;
            }
            if(minn>c)
                minn = c;
        }
        else
            minn = c;
        tc = c;
    }
    cout<<cot<<endl;
 
 
 
    return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值