首页 > 其他分享 >Codeforce Round 916(div3)

Codeforce Round 916(div3)

时间:2023-12-20 14:44:50浏览次数:21  
标签:int res cin Codeforces -- 枚举 Codeforce 916 div3

Codeforces Round 916(div3)

[Problem - A - Codeforces]:Problemsolving Log

A.题 直接看样例进行分析,发现每一次出现的字符代表着用了1分钟来看这道题,每道题都有固定的解题时间,只要达到了这个解题时间,就可以将这题解出来 , 答案就要加上1;同时要注意 将解决过的问题 要标记一下;

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    
    while(n --)
    {
        bool st[30];
        memset(st , false , sizeof st);
        int a[27] = {0}; //记得初始化;
        int res = 0 ; //答案;
        
        int time; //这个好像没什么用;
        cin >> time;
        
        string s;
        cin >> s;
        int len = s.size() - 1;
        
        for(int i = 0 ; i <= len ; i ++)
        {
            a[s[i] - 'A'] ++;
            if(a[s[i] - 'A'] >= (s[i] - 'A' + 1) && st[s[i] - 'A'] == false)
           ////s[i]-'A'+1代表解决题目所花费的时间
            {
                res ++;
                st[s[i] - 'A'] = true;
            }
        }
        cout << res << endl;
    }
    return 0;
    
}

[Problem - B - Codeforces]:Preparing for the Contest

B.题 有几次兴奋前面就直接 从小到大输出 ,输出到那个兴奋的数,后面的就要从大到小输出;

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int k;
    cin >> k;
    
    while(k --)
    {
        int n , num;
        cin >> n >> num;
        
        for(int i = 1 ; i <= num; i ++)
        cout << i << " ";
        for(int i = n; i >num ; i --)
        cout << i << " ";
        
        cout << endl;
        
    }
    return 0;
}

[Problem - C - Codeforces]:Quests

C.题贪心的思想,同是结合了前缀和,我感觉也有枚举的一些地方;

a[i]:代表着第一次完成前 i 个任务所获得的经验值;

b[i]:代表着重复完成第前 i 个任务的最大经验;(我们重复做的肯定是 那个经验值最大的那个)

res :经过枚举,如果完成第 i 个任务后 k 有剩余 那么我们就将重复做那个经验值最大的任务;

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;

int main()
{
    int m;
    cin >> m;

    while(m --)
    {
        int n , k;
        cin >> n >> k;
        int a[N] , b[N];
        for(int i = 1 ; i <= n ; i ++)
        {
            cin >> a[i];
            a[i] += a[i - 1];
        }
        b[0] = 0;
        for(int i = 1; i <= n ; i ++)
        {
            cin >> b[i];
            b[i] = max(b[i] , b[i - 1]); //只保留最大的那个重复完成的值;
        }

        int res = -2e9;
        //枚举完成到第几个任务,剩余的任务机会 都用来做重复的任务;
        for(int i = 1 ; i <= n ; i ++)
        {
            res = max(res , a[i] + (k - i) * b[i]);
            if(i == k) break; //注意有可能 k比n要小 完成k个任务后就要break;
        }
        cout << res << endl;
    }

    return 0;
}

[Problem - D - Codeforces]:Three Activities

D.暴力枚举的话可以做 不过需要注意写成函数 并且关闭同步流,但是我们可以优化,发现我们只需要每个项目的相对最大值,同时满足,天数各不相同,所以我们只需要存下来每个项目里面 ,经过排序后 三个最大值,在这三个最大值里面进行枚举,减少了枚举的量;

using namespace std;
const int N = 1e6 + 10;

int main()
{
    int m;
    cin >> m;

    while(m --)
    {
        int n , k;
        cin >> n >> k;
        int a[N] , b[N];
        for(int i = 1 ; i <= n ; i ++)
        {
            cin >> a[i];
            a[i] += a[i - 1];
        }
        b[0] = 0;
        for(int i = 1; i <= n ; i ++)
        {
            cin >> b[i];
            b[i] = max(b[i] , b[i - 1]); //只保留最大的那个重复完成的值;
        }

        int res = -2e9;
        //枚举完成到第几个任务,剩余的任务机会 都用来做重复的任务;
        for(int i = 1 ; i <= n ; i ++)
        {
            res = max(res , a[i] + (k - i) * b[i]);
            if(i == k) break; //注意有可能 k比n要小 完成k个任务后就要break;
        }
        cout << res << endl;
    }

    return 0;
}

标签:int,res,cin,Codeforces,--,枚举,Codeforce,916,div3
From: https://www.cnblogs.com/volapex-lord/p/17916486.html

相关文章

  • Codeforces Round 916 (Div. 3)(A~E2)
    A统计一下每个字母的出现次数然后输出即可#include<bits/stdc++.h>#definerep(i,a,b)for(registerinti=(a);i<=(b);++i)#definefep(i,a,b)for(registerinti=(a);i>=(b);--i)#definelsp<<1#definersp<<1|1#definePIIpair<int,int&......
  • [Codeforces] CF1795C Tea Tasting
    CF1795CTeaTasting题意有\(n\)个人和\(n\)杯茶,第\(i\)个人每次会喝\(b_i\)毫升的茶。第\(i\)杯茶有\(a_i\)毫升。总共会喝\(n\)轮茶,第\(j\)轮第\(i\)个人会尝试喝第\(i+1-j\)杯茶。喝的量为\(\min(a_{i+1-j},b_i)\)毫升,并且使\(a_{i+1-j}\)减少\(\mi......
  • Educational Codeforces Round 160 (Rated for Div. 2) A~C
    A.RatingIncrease题意:将一个字符串分成两个整数a和b,要求没有前导0,且a<b思路:遍历字符串s,若当前位置不是0,则拆分字符串,比较大小//#include<bits/stdc++.h>#include<iostream>#include<string>#include<cstring>#include<vector>#include<algorithm>#inclu......
  • Educational Codeforces Round 160 (Rated for Div. 2)
    基本情况A题秒了。B题卡了实在太久,BC题最后虽然都过了,但是耗时太久。感觉C对我来说更好写。B.SwapandDelete经典+3。总是一条路偏要走到黑了才会想着换思路,早该换了。一开始想了一大堆乱七八糟的思路,但都错了。后面往简单了想,这题毕竟最后必须要左对齐的,直接从左往右比......
  • 【题解】CodeForces-1913
    CodeForces-1913ARatingIncrease依题意模拟。提交记录:Submission-CodeForcesCodeForces-1913BSwapandDelete交换免费就是能任意重排,从头开始尽量填相反的,剩下只能删去了。提交记录:Submission-CodeForcesCodeForces-1913CGamewithMultiset从大到小能减则减一定......
  • 【题解】CodeForces-1905
    CodeForces-1905AConstructiveProblems发现沿着对角线放就行了,答案是\(\max(n+m)\)。提交记录:Submission-CodeForcesCodeForces-1905BBegginer'sZelda最优操作每次删两个叶子(除了最后一次只剩两个节点),所以答案是叶子个数除以二上取整。提交记录:Submission-CodeForc......
  • Codeforces Round 834 (Div. 3)
    CodeforcesRound834(Div.3)A.Yes-Yes?题意:就是Y后面跟e,e后面跟s,s后面跟Y#include<iostream>usingnamespacestd;voidsolve(){stringx;cin>>x;intl=x.size();if(l==1){if(x[0]!='Y'&&x[0]!='e&#......
  • Codeforces Round 839 (Div. 3)
    CodeforcesRound839(Div.3)A.A+B?跳过太水了、、、、、#include<bits/stdc++.h>usingnamespacestd;intmain(){intt;cin>>t;while(t--){inta,b;scanf("%d+%d",&a,&b);cout<<a+......
  • Educational Codeforces Round 131 (Rated for Div. 2)
    基本情况AB秒了。C知道是二分答案,check死活写不出来。C.ScheduleManagementProblem-C-Codeforces错误分析这题比较绕,搞了一个对应关系,大脑转不过来。写check的时候完全想不出合理的思路。很明显的要用桶来计数,但是怎么用不知道了。看了题解后发现,check不能遍历任......
  • Educational Codeforces Round 159 (Rated for Div. 2)
    EducationalCodeforcesRound159(RatedforDiv.2)A-BinaryImbalance解题思路:有一对\((0,1)\),那么\(0\)就能无限增长。代码:#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=2e5+10;typedefpair<ll,ll>pii;constllm......