上海市计算机学会竞赛平台三星级挑战


此文章仅供学习交流,不得抄袭刷分!!!
2022/5/26 目前以全部更完

最大回撤

#include <iostream>
using namespace std;

int main()
{
   
    int n, min = -100001, large = -100001, a;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
   
        cin >> a;
        min = max(min, large - a);
        large = max(large, a);
    }
    cout << min;
    return 0;
}

最后一击

#include <iostream>
using namespace std;

long long n, a, b, x = 1, y = 1, cont = 0, sum = 0;
bool q = false, g = false, d = false;
int main()
{
   
	cin.tie(0);
	cin >> n >> a >> b;
	while(sum < n)
	{
   
		if (a * y > b * x)
			sum++, x++, q = true, g = false, d = false;
		else if (a * y == b * x)
			sum += 4, x++, y++, q = false, g = false, d = true;
		else
			sum++, y++, q = false, g = true, d = false;
	}
	if (q == true)	
		cout << "A";
	else if (g == true)	
		cout << "B";
	else if (d == true)	
		cout << "C";

	return 0;
}

平衡点

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int n;
long long a[100005];
long long pre[100005], suf[100005];
long long ans, L, R;
int main()
{
   
	std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
   
		cin >> a[i];
		pre[i] = pre[i - 1] + a[i]; //前缀和
		ans += a[i] * (i - 1); //初始为最大
	}
	for(int i = n; i >= 1; i--)
		suf[i] = suf[i + 1] + a[i]; //后缀和
	R = ans;
	for(int i = 1; i <= n; i++)
	{
   
		L += pre[i];
		R -= suf[i + 1];
		ans = min(ans, abs(L - R));
	}
	cout << ans;
	return 0;
}

栈的判断

#include <iostream>
#include <cmath>
#include <stack>
using namespace std;

int n, x;
stack<int>stak;
int main() {
   
	std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) {
   
		int tmp;
		cin >> tmp;
		if(stak.empty() && x <= tmp) {
   
			while(x < tmp) 
				stak.push(x++);
			x++;
			}
		else if(stak.top() == tmp)
			stak.pop();
		else if(stak.top() < tmp) {
   
			while(x < tmp) 
				stak.push(x++);
			x++;
			}
		else if(stak.top() > tmp) {
   
			cout << "Invalid" << endl;
			return 0;
			}
		}
	cout << "Valid" << endl;
	return 0;
	}

排队安排

#include <iostream>
#include <algorithm>
using namespace std;

int n, a[1000000], c;
int main() {
   
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	
	sort(a, a + n);
	for (int i = 0; i < n; ++i)
		if (c <= a[i])
			++c;

	cout << c << endl;
	return 0;
}

逆波兰式

#include<bits/stdc++.h>
using namespace std;
stack<int> st;
string line;
int main() {
   
    getline(cin,line);
    for(int i=0; i<line.size(); i++) {
   
        char tem=line[i];
        if(tem==' ') continue;
        if(tem<='9' and tem>='0') {
   
            st.push(tem-'0');
            continue;
        }
        int now=0;
        int b= st.top();
        st.pop();
        int a=st.top();
        st.pop();
        if(tem=='+') st.push((a+b)%10);
        if(tem=='-') st.push((a-b)%10);
        if(tem=='*') st.push(a*b%10);
    }
    int ans=st.top();
    ans=ans%10;
    if (ans<0) ans=10+ans;
    cout<<ans;
    return 0;
}

股票市场

#include <iostream>
using namespace std;
long long n, m, stock = 0, a[100001];
bool flag = false;
int main() {
   
	cin.tie(0);
	cin >> n >> m;
	cin >> a[0]
  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dsmtyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值