Codeforces Round 957 (Div. 3) A~D

A. Only Pluses

算法:模拟

链接:Problem - A - Codeforces

思路:输入三个数 执行五次 每次排序让最小的数自增即可

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
ll a[4];
void solve(){
   cin>>a[1]>>a[2]>>a[3];
   ll t=5;
   while(t--){
    sort(a+1,a+4);
    a[1]++;
    
   }
   cout<<a[1]*a[2]*a[3]<<"\n";
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

B. Angry Monk

算法:贪心

链接:Problem - B - Codeforces

思路:因为只有分解成1才可以合成 且最终需要合成一个 所以先将除最大的以外的所有数分解成1  第i个数需要操作a[i]-1次 然后再把这些数都和最大的那个合成

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
ll a[Q];
void solve(){
   ll n,m;cin>>n>>m;
   ll ma=0;ll ans=0;
   for (ll i = 1; i <= m; i++)
   {
    cin>>a[i];ma=max(ma,a[i]);
   }
   for (ll i = 1; i <= m; i++)
   {
    ans+=a[i]-1;
   }
   ans-=ma-1;
   ans+=(n-ma);
   cout<<ans<<"\n";
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

C. Gorilla and Permutation

算法:构造 贪心

链接:Problem - C - Codeforces

思路:因为m是小于k的 所以最优解肯定是先让大于k的部分在最前面从大到小 使得Σf最大 然后把大于m的随意排列 最后是小于m的从小到大排列 这样可以使得答案最小

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
ll a[Q];
void solve(){
   ll n,m,k;cin>>n>>m>>k;
    for (ll i = n; i >= k; i--)
    {
        cout<<i<<" ";
    }
    for (ll i = m+1; i < k; i++)
    {
        cout<<i<<" ";
    }
    for (ll i = 1; i <= m; i++)
    {
        cout<<i<<" ";
    }cout<<"\n";
    
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

D. Test of Love

算法:模拟 贪心

链接:Problem - D - Codeforces

思路:因为在水中不能跳跃 所以当连续的水的情况 鳄鱼之前的格子都是不能走的 然后 如果能跳跃的距离内有木桩 就跳到木桩上 没有木桩则跳跃到最远的水里 然后游到面前最近的岸上 统计游泳格数 计算是否小于可以游泳的个数 若最远的河前面有鳄鱼也不行

PS:代码cnt是我能跳的格数 有L则刷新格数 一直到头没有L则游泳 并判断是否有鳄鱼

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
void solve(){
   ll n,m,k;cin>>n>>m>>k;
    string s;cin>>s;
    s="L"+s+"L";
    ll now=0;ll cnt=m;
    for (ll i = 1; i <= n+1; i++)
    {
        cnt--;
        if(s[i]=='L'){
            cnt=m;
            continue;
        }
        if(cnt==0){
            if(s[i]=='W'){
                for (ll j = i+1; j <= n+1; j++)
                {
                    if(s[j]=='C'){
                        cout<<"NO\n";
                        return;
                        
                    }
                    if(s[j]=='L'){
                        k-=j-i;
                        if(k<0){
                            cout<<"NO\n";
                            return;
                        }
                        i=j;
                        cnt=m;
                        break;
                    }
                }
                
            }else{
                cout<<"NO\n";
                return;
            }
        }
    }
    cout<<"YES\n";
}
int main(){
    ios;ll _=1;cin>>_;
    while (_--)solve();
    return 0;
}

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值