首页 > 其他分享 >Codeforces Round 916 (Div. 3)

Codeforces Round 916 (Div. 3)

时间:2024-07-10 09:09:02浏览次数:11  
标签:916 return int ll Codeforces ++ num Div include

A. Problemsolving Log

签到题,对于给出的字符串,记录每个字母出现的次数,然后遍历一遍,如果对应的字母出现的次数大于它的位次,则说明该题被解出来了,最后输出解题数量即可

点击查看代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int N = 2*1e5 + 10;
void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int st[27] = { 0 };
    int count = 0;
    for (int i = 0; i < s.size(); i++)
    {
        st[s[i] - 'A' + 1]++;
    }
    for (int i = 1; i < 27; i++)
    {
        if (st[i] >= i) count++;
    }
    cout << count << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

B. Preparing for the Contest

排序问题,兴奋 \(k\) 次,即前 \(1-k\) 按照升序排列,剩下的按照降序排序即可

点击查看代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) {            //最大公约数
    while (y ^= x ^= y ^= x %= y);
    return x;
}
ll lcm(ll x, ll y) {           //最小公倍数
    return x * y / gcd(x, y);
}
void solve() {
    int x, k;
    cin >> x >> k;
    int no = 0;
    for (int i = 1; i<=x; i++)
    {
        if (k != 0)
            cout << i << " ";
        else
        {
            no = i;
            break;
        }
        k--;
    }
    for (int i = x; i >= no; i--)
    {
        cout << i << " ";
    }
    cout << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

C. Quests

暴力贪心,先用前缀和预处理数组 \(a\) ,之后对于数组 \(b\) ,用一个数组 \(d[i]\) 表示前 \(i\) 个中最大的 \(b\) ,最后遍历一遍, \(ans\) 取最大的 \(c[i] + (y-i)\times d[i]\)

点击查看代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) {            //最大公约数
    while (y ^= x ^= y ^= x %= y);
    return x;
}
ll lcm(ll x, ll y) {           //最小公倍数
    return x * y / gcd(x, y);
}
void solve() {
    ll x, y;
    cin >> x >> y;
    vector<ll>a(x+1);
    vector<ll>b(x+1);
    vector<ll>c(x + 1);
    vector<ll>d(x + 1);
    d[0] = 0;
    c[0] = 0;
    ll ans = 0;
    for (int i = 1; i <=x; i++)
    {
        cin >> a[i];
        c[i] = a[i] + c[i - 1];//前缀和
       // cout << c[i] <<" ";
    }
    for (int i = 1; i <=x; i++)
    {
        cin >> b[i];
        d[i] = max(d[i - 1], b[i]);//最大
    }
    for (int i = 1; i <=min(x,y); i++)
    {
        ll sum = c[i] + (y - i) * d[i];
        //cout << sum << " ";
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

D. Three Activities

暴力打表,先将每一个活动都排序(找出最多人数的3天),然后这3天互相排列组合,去除天数相同的,剩下的找最大值即是答案

点击查看代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
ll gcd(ll x, ll y) {            //最大公约数
    while (y ^= x ^= y ^= x %= y);
    return x;
}
ll lcm(ll x, ll y) {           //最小公倍数
    return x * y / gcd(x, y);
}
struct no {
    ll num;
    ll day;
}a[N],b[N],c[N];

bool cmp(no x, no y)
{
    return x.num > y.num;
}
void solve() {
    ll x;
    cin >> x;
    for (int i = 0; i < x; i++)
    {
        cin >> a[i].num;
        a[i].day = i;
    }
    for (int i = 0; i < x; i++)
    {
        cin >> b[i].num;
        b[i].day = i;
    }
    for (int i = 0; i < x; i++)
    {
        cin >> c[i].num;
        c[i].day = i;
    }
    sort(a, a + x, cmp);
    sort(b, b + x, cmp);
    sort(c, c + x, cmp);//由大到小排序
    ll ans = 0;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (a[i].day != b[j].day && a[i].day != c[k].day && b[j].day != c[k].day)
                    ans = max(a[i].num + b[j].num + c[k].num, ans);
            }
        }
    }
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

E. Game with Marbles

贪心排序问题,这一题 \(easy\) 和 \(hard\) 差别不大, \(easy\) 应该暴力模拟可以过。计算每一组的权值, \(Alice\) (简称 \(A\) ), \(Bob\) (简称 \(B\) ) 对于 \(A\) 来说,选择的一组所获得的权值是 \(a_i+b_i-1\) (消除 \(b_i\) 等于加 \(b_i\) 与 \(B\) 拉开了 \(b_i\) 的差距且保留了自己的剩余的 \(a_i-1\) ,因此是 \(a_i+b_i-1\) );同理,对于 \(B\) 来说,也是这样,因此无论是 \(A\) 操作时还是 \(B\) 操作时,所选择的都是 \(a_i+b_i\) 最大值那一组 (每一组的权值都有 -1 因此可以仅比较 \(a_i+b_i\)) , 使用结构体存储每一组石子的数量和和组号,对石子数量进行排序,之后由大到小进行模拟即可。

点击查看代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
ll gcd(ll x, ll y)
{            //最大公约数
    while (y ^= x ^= y ^= x %= y);
    return x;
}
ll lcm(ll x, ll y) {           //最小公倍数
    return x * y / gcd(x, y);
}
struct non {
    ll num;
    ll step;
}v[10];
bool cmp(non x, non y) {
    return x.num < y.num;
}

void solve() {
    ll x;
    cin >> x;
    vector<ll>a(x + 1);
    vector<ll>b(x + 1);
   // vector<ll>v(x + 1);
    for (int i = 0; i < x; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < x; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < x; i++)
    {
        v[i].num = a[i] + b[i] - 1;
        v[i].step = i;
    }
    sort(v, v + x,cmp);
    //for (int i = 0; i < x; i++)
    //{
    //    cout << v[i].num << " ";
    //}
    ll sum = 0;
    int j = 1;
    if (x % 2 == 0)
    {
        for (int i = x-1; i>=0; i--)
        {
            //cout << v[i] << " ";
            if (j == 1)
            {
                sum += a[v[i].step] - 1;
            }
            else
                sum -= b[v[i].step] - 1;
            j *= -1;
        }
    }
    else
    {
        for (int i = x - 1; i >= 0; i--)
        {
            if (i ==0)
            {
                sum += a[v[i].step] - 1;
                break;
            }
            else
            {
                if (j == 1)
                {
                    sum += a[v[i].step] - 1;
                }
                else
                    sum -= b[v[i].step] - 1;
            }
            j *= -1;
        }
    }
    cout << sum << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

标签:916,return,int,ll,Codeforces,++,num,Div,include
From: https://www.cnblogs.com/haggard/p/18293139

相关文章

  • Codeforces Round 956 (Div. 2) 部分题解A~C
    A.ArrayDivisibility题目大意构造长度为n的数组,满足:所有j的aj之和可以被k整除,其中j是k的倍数,k的取值为1~n。思路构造序列1->n即可满足条件。代码实现voidsolve(){  lln;cin>>n;  for(inti=1;i<=n;i++)cout<<i<<"";  cout<<"\n"......
  • joi2022_yo2_c 国土分割 (Land Division) 题解
    国土分割(LandDivision)推销我的洛谷博客。题意给定一个\(n\timesm\)的矩阵\(a\),你需要选择在横向或纵向分割至少一次,使得每个分割出来的小矩阵的\(a_{i,j}\)之和相等。数据范围\(1\leqslantn,m\leqslant50\)。\(1\leqslanta_{i,j}\leqslant10^5\)。思......
  • Codeforces Round #956 (Div. 2) and ByteRace 2024
    Preface连着好几天因为熬夜看LOL比赛导致白天精神萎靡,都没精力VP了而且明天就要开始统一训练了,趁着最后一天补一下前两天因为看比赛没打的这场吧这场只能说是战术正确,想了会E没啥思路就马上转头去把F写了,后面回头慢慢想E也想出来了,最后极限2h14min出了EA.ArrayDivisibility......
  • codeforces 955 div 2 D
    题目链接D.Beautyofthemountains题目大意解题思路首先记录所有雪山和没有雪山两种山峰的高度差为\(tot\),然后对于每个可能的子矩,我们可以每次给所有山峰都加一或者减一,因此只要计算出矩阵内两种山峰的个数差的绝对值我们就能得到每次操作该子矩阵对tot的贡献\(z_{i}......
  • Codeforces Round956(div2) A~C
    A.ArrayDivisibility题意:对于所有k=1~n,能被j=1~n整除,要求以这些j作为下标a[j]的和也能够被k整除思路:题目有点绕,但是仔细读懂题目其实会发现,其实就是从1到n按顺序输出一遍...,别被样例忽悠了voidsolve(){ intn; cin>>n; for(inti=1;i<=n;i++){ cout......
  • Codeforces Round 953(Div.2) 题解(A-E)
    CodeforcesRound953(Div.2)题解(A-E)A题意Alice有n本书,第一本书有\(a_1\)页,序号为1,第二本书有\(a_2\)页,序号为2,……,第n本书有\(a_n\)页,序号为n。Alice将把所有书分成两堆,并阅读每一堆中序号最大的一本书。Alice喜欢读书,请你告诉她,她最多可以读多少页的书。Solution第......
  • P0916VB 触点输入模块
    型号:P0916VB类别:触点输入模块成色:全新,非全新质保:一年P0916VB触点输入模块的工作原理基于触点信号的检测与转换。当外部设备的触点闭合或断开时,会产生相应的电信号变化。触点输入模块通过内部的电路设计,能够检测到这种电信号的变化,并将其转换为控制系......
  • CodeForces CF1980C Sofia and the Lost Operations 题解 但是最后TLE 仅供思路参考
    CodeForcesCF1980CSofiaandtheLostOperations题解嗨嗨,又来了啊,蒟蒻再来一篇题解SofiaandtheLostOperations题面翻译索菲亚有一个包含$n$个整数的数组$a[1],a[2],…,a[n]$。有一天她对这个数组感到厌倦,于是决定顺序地对其应用$m$个修改操作。每个修改操作由一......
  • Codeforces Round #956 (Div. 2) C. Have Your Cake and Eat It Too
    CodeforcesRound#956(Div.2)C.HaveYourCakeandEatItToo题目大意:有长度为nnn的数组a......
  • / 用上指针 ,定义函数实现:终端输入 add + sub - mul * div / 执行 两个数 的加减乘除
    #include<stdio.h>#include<string.h>intmy_add(intdata1,intdata2){  returndata1+data2;}intmy_sub(intdata1,intdata2){  returndata1-data2;}intmy_mul(intdata1,intdata2){  returndata1*data2;}intmy_di......