Codeforces Round #778 (Div. 1 + Div. 2, based on Technocup 2022 Final Round)

Dashboard - Codeforces Round #778 (Div. 1 + Div. 2, based on Technocup 2022 Final Round) - Codeforceshttps://codeforces.com/contest/1654

A Maximum Cake Tastiness

找最大的前两个数就好了,自己挑选第二大的区间然后把它转到第一大的后一个位置

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
const int maxn = 1e3+10;
int num[maxn];
#define PI pair<int,int>
int main(){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        for(int i = 1;i<=n;i++)
            cin>>num[i];
        int m1 = -1,m2 = -1;
        for(int i = 1;i<=n;i++){
            if(num[i]>m1){
                m2 = m1;
                m1 = num[i];
            }
            else if(num[i]>m2)
                m2 = num[i];
        }
        cout<<m1+m2<<endl;
    }
}

B. Prefix Removals

一个一个删过去就好了,因为你会发ababbab这样的,你删ab和先删a后删b是一样的,模拟一遍一个一个删过去就好了

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
const int maxn = 1e3+10;
#define PI pair<int,int>
int main(){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int t;
    cin>>t;
    string s;
    while(t--){
        cin>>s;
        int num[30] = {};
        for(int i = 0;i<s.size();i++){
            int now = s[i]-'a'+1;
            num[now] = i;
        }
        
        int i;
        for(i = 0;i<s.size();i++){
            int now = s[i]-'a'+1;
            if(num[now]==i)
                break;
        }
        for(;i<s.size();i++)
            cout<<s[i];
        cout<<endl;
    }
}
//删除最长的前缀(前缀属于非前缀部分的字串)
//一个一个删

C. Alice and the Cake

这题不需要从结果推蛋糕,直接加和模拟切蛋糕就好了,两种做法,一种双堆模拟,一种bfs

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int maxn = 1e9+10;


int main(){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int t;
    cin>>t;
    while(t--) {
        int n,x;
        cin >> n;
        long long sum = 0;
        priority_queue<long long>fin,cake;
        for(int i = 1;i<=n;i++){
            cin>>x;
            sum+=x;
            fin.push(x);
        }
        cake.push(sum);
        while(!fin.empty()&&!cake.empty()){
            long long now = cake.top();
            cake.pop();
            if(fin.top()==now)
                fin.pop();
            else if(now<fin.top()) 
                break;
             //如果蛋糕顶比cake顶还小,说明切不出来了(同时考虑到了 1的情况处理)
            else{
                cake.push(now/2);
                cake.push(now/2+now%2);
            }
        }
        if(fin.empty()&&cake.empty())
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}
//切最大的蛋糕产生的一定是结果中对应最大的蛋糕(因为切法是固定的)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值