Educational Codeforces Round 92 (Rated for Div. 2)【差!!!!!】

A. LCM Problem

在这里插入图片描述
思路:自己从那里乱试!都错了,太傻了。虽然A了,但多少都有点狼狈
直接找范围内有没有2*l,有就输出l和2 * l;否则输出-1

B. Array Walk

题意:就是一排数字,你总共可以行走K步,每走到一个地方可以获得那个a[i],其中你可以向左走z次并且 不能连续走两次左,你可以获得最大的S,
思路:当时自己想的就是在前k+1个元素中找到最大值然后在最大值的两边蹦来蹦去,但后来证实是错误的想法。、
思路:算两两相邻的和,算前n项的和。然后你在k+1开始向左走,写个for循环然后开始算想左走多少步和合适。。。。代码有详解!

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <vector>
#include <set>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long ll;
using namespace std;
const int maxn = 1e5 + 10;
ll sum[maxn], a[maxn], s2[maxn];
int main() 
{
    
    
    int t;
    cin >> t;
    ll n, k, z;
    while (t--)
    {
    
    
        cin >> n >> k >> z;
        for (int i = 1; i <= n; i++)
        {
    
    
            cin >> a[i];
            sum[i] = sum[i-1] + a[i];//计算前i项和
        }
        for (int i = 1; i < n; i++)
            s2[i] = a[i] + a[i + 1];//s2计算相邻两个a[i] a[i-1]的和
        ll ans = sum[k + 1], ed = k + 1, m = -1;//ans是全往右走的和
        for (int i = 1;i <= z; i++)//向左走
        {
    
    
            ed = k+1-i*2;//走完i 到哪里了呀?
            m = -1;
            if (ed<1) break;
            for (int j = 1; j<= ed; j++)
                m = max(m, s2[j]);//然后你在前ed里面找最大的两相和,这样就不用去遍历了
            ans = max(sum[ed]+m*i, ans);
        }
        cout << ans << endl;
    }
   
}

C. Good String

题意:
在这里插入图片描述
在这里插入图片描述
给你一个串t问最少删除几个 可以让上边那俩相等!
思路:

大佬链接
https://blog.csdn.net/jziwjxjd/article/details/107680437

在这里插入图片描述

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <vector>
#include <set>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long ll;
using namespace std;
int t, v[100]; char a[200005];
int run(int q, int w, int n)
{
    
    
    char qq = q + '0';
    char ww = w + '0';
    int k = 0, t = 0;
    for (int i = 1; i <= n; i++)//^操作,0变1,1变0 
    {
    
    
        if (a[i] == qq && k == 0) k ^= 1;
        if (a[i] == ww && k == 1)
        {
    
    
            k ^= 1; t += 2;
        }
    }
    return t;
}
int main() 
{
    
    
    int t;
    cin >> t;
    while (t--)
    {
    
    
        cin >> (a + 1);
        int ans = 0; int n = strlen(a + 1);
        memset(v, 0, sizeof v);
        for (int i = 1; i <= n; i++)
        {
    
    
            v[a[i] - '0']++;
            ans = max(ans, v[a[i] - '0']);
        }
        for(int i=0;i<=9;i++)
            for (int j = 0; j <= 9; j++)
            {
    
    
                if (i == j) continue;
                ans = max(ans, run(i, j, n));
            }
        cout << n - ans << endl;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_45988242/article/details/107700749