Codeforces Round #621 (Div. 1 + Div. 2)ABC

A. Cow and Haybales

在这里插入图片描述

从最左边的移到第一个才能实现最大化
即从左到右判断

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int a[105];
int t;
int main(){
    cin>>t;
    while(t--){
        int n,d;cin>>n>>d;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        int sum=a[1];
        for(int i=2;i<=n;i++){
            if(a[i]*(i-1)<=d){
                sum+=a[i];
                d-=a[i]*(i-1);
            }
            else{
                sum+=(d/(i-1));
                break;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

B. Cow and Friend

在这里插入图片描述

如果有和x相等的距离,输出1
否则记录最大的数字maxs,输出max(2,(d-1)/maxs)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int a[100005];
int main(){
    int t;cin>>t;
    while(t--){
        int n,x;cin>>n>>x;
        int maxs=-1;
        int flag=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(a[i]==x)flag=1;
            maxs=max(maxs,a[i]);
        }
        if(flag==0)cout<<max(2,(x+maxs-1)/maxs)<<endl;
        else cout<<1<<endl;
    }
    return 0;
}

C. Cow and Message

在这里插入图片描述

字符只可取1位或2位
若可取3位,则若取3位中的其中2位,必不小于3位的数量
从结尾到开头进行枚举
注意数据范围long long

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
ll a[30];
ll b[30][30];
int main(){
    string s;cin>>s;
    ll maxs=-1;
    for(int i=0;i<s.length();i++){
        a[s[i]-'a']++;
        maxs=max(maxs,a[s[i]-'a']);
    }
    for(int i=s.length()-1;i>=1;i--){
        int c=s[i]-'a';
        a[c]--;
        for(int j=0;j<26;j++){
            b[j][c]+=a[j];
            maxs=max(maxs,b[j][c]);
        }
    }
    cout<<maxs;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值