本文主要是介绍Daydreaming Stockbroker Gym - 101550D(贪心),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:
在极大值点卖,极小值点买。
可以看做是递增的部分一直卖
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>using namespace std;
typedef long long ll;ll a[1005];
int main() {int n;scanf("%d",&n);for(int i = 1;i <= n;i++) {scanf("%lld",&a[i]);}ll ans = 100;for(int i = 2;i <= n;i++) {if(a[i] > a[i - 1] && ans >= a[i - 1]) {if(ans / a[i - 1] > 100000) {ans -= a[i - 1] * 100000;ans += a[i] * 100000;}else {ll add = ans / a[i - 1];ans %= a[i - 1];ans += add * a[i];}}}printf("%lld\n",ans);return 0;
}
这篇关于Daydreaming Stockbroker Gym - 101550D(贪心)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!