Educational Codeforces Round 55 (Rated for Div. 2) A B C

A. Vasya and Book

题解:分三种情况,看哪一种最优即可。是直接翻还是翻到最左再到 y y y,还是翻到最右再到 y y y

代码

#include<bits/stdc++.h>

using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
#endif
	int T,n,x,y,d;
	cin>>T;
	while(T--) {
		cin >> n >> x >> y >> d;
		int t = abs(y - x), cnt = 1e9;
		if(t % d == 0) {
			cnt = t / d;
		}
		if((y - 1) % d == 0){
			cnt = min(cnt, (int)ceil(1.0 * x / d) + (y - 1) / d);
		}
		if((n - y) % d == 0) {
			cnt = min(cnt, (int)ceil((n - x) * 1.0 / d) + (n - y) / d);
		}
		if(cnt != 1e9)
			cout << cnt << endl;
		else
			puts("-1");
	}
    return 0;
}

B. Vova and Trophies

题解:维护两段和最大的连续子序列即可,并且保证最大间隔不会超过 1 1 1

代码

#include <bits/stdc++.h>

using namespace std;

int main() {
    string str;
    int n;
    cin >> n;
    cin >> str;
    int res = 0;
    int cntG = 0, sumG = 0, ccG = 0;
    for (int i = 0; i < n; ++i) {
        if (str[i] == 'G') {
            sumG++;
            cntG++;
        } else {
            ccG = cntG;
            cntG = 0;
        }
        res = max(res, ccG + cntG + 1);
    }
    res = min(sumG, res);
    cout << res << endl;
    return 0;
}

C. Multi-Subject Competition

题解:根据能力值降序排序,考虑所选科目只有 i i i个人的最大能力值,然后前缀和,暴力枚举。

#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
vector <LL> v[100100];
LL a[100100];
int main() {
    LL n, m, x, y, i;
    cin >> n >> m;
    for (i = 0; i < n; i++) {
        cin >> x >> y;
        v[x].push_back(y);
    }
    for (i = 1; i <= m; i++) {
        if (v[i].size() > 0) {
            sort(v[i].rbegin(), v[i].rend());
            for (LL j = 1; j < v[i].size(); j++) {
                v[i][j] = v[i][j] + v[i][j - 1];
            }
        }
    }
    for (LL i = 1; i <= m; i++) {
        for (LL j = 0; j < v[i].size(); j++) {
            if (v[i][j] > 0)
                a[j] += v[i][j];
        }
    }
    LL Answer = 0;
    for (LL i = 0; i <= n; i++)
        Answer = max(Answer, a[i]);
    cout << Answer;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值