Codeforces Round 962 (Div. 3)

传送门:https://codeforces.com/contest/1996

第一题:Legs

题意:思路:贪心(尽可能选择牛)

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
    int n;
    cin >> n;
    cout << n / 4 + ( n % 4 ) / 2 <<endl;
}
int main()
{
    int tt; cin >> tt;
    while (tt--)solve();
    return 0;
}

第二题:Scale

题意:

思路:(模拟题)

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 10;
int a[N][N];
int b[N][N];
void solve()
{
    memset(a, 0, sizeof a);
    memset(b, 0, sizeof b);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        string s;
        cin >> s; s = " " + s;
        for (int j = 1; j <= n; j++) {
            a[i][j] = s[j] - '0';
        }
    }
    int row = 0; int col = 0;
    for (int i = 1; i <= n; i += k)
    {
        row++;
        for (int j = 1, col = 1; j <= n; j += k, col++)
        {
            b[row][col] =  a[i][j];
        }
    }
    for (int i = 1; i <= row; i++)
    {
        for (int j = 1; j <= row; j++)cout << b[i][j];
        cout << endl;
    }
   
}
int main()
{
    int tt; cin >> tt;
    while (tt--)solve();
    return 0;
}

第三题:Sort

思路:(前缀和 + 模拟)

1. 设 f [i][j] 为前i个字母中 , 字符 j + 'a' 出现的次数

2. 一段区间中,a中字符串中的字符数 - b中字符串中的字符数 -> 替换的次数

eg:        1   a b c d e g g

             2   g g  b e f  f d

1中字符串 'a' 和 'c' 的个数多于 2中的字符串  答案为2

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int f[N];
int ch1[N][27];
int ch2[N][27];
void solve()
{
    memset(f, 0, sizeof f);
    memset(ch1, 0, sizeof ch1);
    memset(ch2, 0, sizeof ch2);
    int n, q;
    cin >> n >> q;
    string s1, s2;
    cin >> s1 >> s2;
    s1 = " " + s1; s2 = " " + s2;
   
    for (int i = 1; i <= n; i++)
    {
        ch1[i][s1[i] - 'a' + 1]++; ch2[i][s2[i] - 'a' + 1]++;
        for (int j = 1; j <= 26; j++)ch1[i][j] += ch1[i - 1][j], ch2[i][j] += ch2[i - 1][j];
    }

    while (q--)
    {
        int l, r;
        cin >> l >> r;
        int temp1[27] = { 0 };
        int temp2[27] = { 0 };
        for (int i = 1; i <= 26; i++)temp1[i] = ch1[r][i] - ch1[l - 1][i];
        for (int i = 1; i <= 26; i++)temp2[i] = ch2[r][i] - ch2[l - 1][i];
        for (int i = 1; i <= 26; i++)temp1[i] -= temp2[i];
        int res = 0;
        for (int i = 1; i <= 26; i++)if (temp1[i] > 0)res += temp1[i];
        cout << res << endl;
    }
    // cout << endl;
}
int main()
{
    int tt; cin >> tt;
    while (tt--)solve();
    return 0;
}

第四题:Fun

题意:

思路:

通过枚举 a b , 确定 c 的个数 , 从而确定(a,b,c)的个数

#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n , x;
    cin >> n >> x;
    int ans = 0;
    for( int a = 1; a <= n ; a++)
    {
        for( int b = 1 ; a + b <= x && a * b <= n ; b++)
        {
            ans += min((n - a * b ) / ( a + b ) , x - a - b );
        }
    }
    cout << ans << endl;
}
signed main()
{
    int tt;
    cin >> tt;
    while(tt--)solve();
    return 0;
}

第五题:Decode

题意:

思路:

1. 如何确定一段区间内 0 1 个数相等 -> 将 0 当做 -1 ,1 当做 1处理,若0 1个数相等,则说明这一段区间和为0  f[r] == f[l-1]

2. 如何确定(l , r)对(x,y)的贡献 -> 扩展(x,y), (x,y) 那么x的范围 * y的范围

就是贡献 x * ( n - y + 1 )

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int pre[N];
void solve()
{
    string s;cin>> s;
    int n = s.size();
    s = " " + s;
    for( int i = 1 ;i <= n;i++)
    {
        pre[i] = pre[i-1] + (s[i] == '1' ? 1 : -1);
    }
    map<int,int> cnt;
    cnt[0] = 1; // 初始化
    int ans = 0;
    for( int i = 1; i<= n;i++)// 枚举右端点
    {
        ans = (ans + cnt[pre[i]] * (n - i + 1 )) % mod;
        cnt[pre[i]] = (cnt[pre[i]] + i + 1) % mod;
        // 为什么要 cnt[pre[i]] + i + 1
        // cnt[pre[i]] 因为前面的左边界的选法仍会影响后面 , + 1 是为了保证 pre[r] == pre[l-1] , 此时 i + 1 才是 l 的长度
    }
    cout << ans <<endl;
}
signed main()
{
    int tt;
    cin >>tt;
    while(tt--)solve();
    return 0;
}

Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值