训练记录-cf-di2-866(A-C)

手速场 但是wa了两发 血亏

上蓝了 纪念一下( 不过我还是菜鸡 什么都不会orz

A. Yura's New Name

题意:要形成^^或者^_^的笑脸 最少加多少个^

思路:特判单个^输出1 单个_输出2  首是_ +1 尾是_ +1  其次计算连续的__ ans加上cnt-1个

复制代码
#include<bits/stdc++.h>
#define close     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const ll MAXN = 3e5+7;
const ll mod =1e9+7;
const ll inf =0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;

void solve(){
    string s;cin>>s;
    int n;n=s.length();
    int ans=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        if((i==0)&&s[i]=='_') ans++;
        if((i==n-1)&&s[i]=='_') ans++;
        if(s[i]=='_'){
            cnt++;
        }
        else {
            if(cnt!=0){
                ans+=cnt-1;
            }
            cnt=0;
        }
    }
    if(cnt!=0) ans+=cnt-1;
    if(n==1&&s[0]=='^') ans+=1;
    cout<<ans<<"\n"; 
}
signed main(){
    int t;cin>>t;
    while(t--) 
    solve();
}
View Code
复制代码

B. JoJo's Incredible Adventures

题意:每个字符串向右一位 形成n*n的矩阵 问其中矩形1的面积最大为多少个

思路 矩形面积和连续1的个数有关  记最大连续1个数为m m为奇数 面积就是(n+1)/2的平方

m为偶数,面积就是(n+1)/2和(n+3)/2的乘积 

如果全是1 就输出n*n

复制代码
#include<bits/stdc++.h>
#define close     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const ll MAXN = 3e5+7;
const ll mod =1e9+7;
const ll inf =0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;
#define int ll 
int lowbit(int x){ return x&-x; }
int gcd(int x,int y){int k=0; if(x<y){k=x;x=y;y=k;}while(x%y!=0){k=x%y;x=y;y=k;}return y;}
ll _power(ll a,int b){ll ans=1,res=a;while(b){if(b&1) ans=ans*res%mod;res=res*res%mod;b>>=1;}return ans%mod;}
void solve(){
    string s;cin>>s;
    s=s+s;
    int n=s.length();
    int maxs=0,cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            cnt=0;
        }
        else{
            cnt++;
            maxs=max(cnt,maxs);
        }
    }
    if(maxs==n) {
        n=n/2;
        cout<<n*n<<"\n";
    }
    else{
        n/=2;
        if(maxs==1){
            cout<<1<<"\n";
            return;
        }
        int k=(maxs+1)/2;
        int t;
        if(maxs%2==0)
         t=k+1;
        else t=k;
        cout<<k*t<<"\n";
    }
}
signed main(){
    int t;cin>>t;
    while(t--)
    solve();
}
View Code
复制代码

C. Constructive Problem

题意:你可以进行一次操作 选择数列一段区间 全变成k 然后让数列的mex+1

思路: 假如为01131130 这样 一开始mex为2 要变成3 就要满足 操作后的数列有2且没有3  那就要把包含3的整段都换成2 即 01122220 这个数列比较好 换了之后正常 如果唯一几个的1 和0都在3夹着里面 那么mex就会更小

因此 用map记录各个数字 再删

如果不存在这个3  我们就要不可以把重复的数字换成2 要不就可以把任意更大的数字换成2  记录一下即可

复制代码
#include<bits/stdc++.h>
#define close     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const ll MAXN = 3e5+7;
const ll mod =1e9+7;
const ll inf =0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;
int a[MAXN];
void solve(){
    int n;cin>>n;
    set<int> sz;
    map<int,int> mp;
    int flag=0,res=1,maxs=0,mex=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sz.insert(a[i]);
        mp[a[i]]++;
        if(mp[a[i]]>=2) flag=1;
        maxs=max(a[i],maxs);
    }
    for(auto i:sz){
        if(i==mex) mex++;
        else if(i>mex) break;
    }
    mex++;
    int L=-1,R=-1;
    for(int i=1;i<=n;i++){
        if(a[i]==mex){
            L=i;break;
        }
    }
    for(int i=n;i>=1;i--){
        if(a[i]==mex){
            R=i;break;
        }
    }
    if(R==-1&&(flag||maxs>mex)){
        cout<<"Yes\n";
        return;
    }
    mp[mex-1]=inf;
    for(int i=L;i<=R;i++){
        mp[a[i]]--;
        if(a[i]<mex&&mp[a[i]]==0) res=0;
    }
    if(res){
        cout<<"Yes\n";
    }
    else cout<<"No\n";
}
signed main(){
    int t;cin>>t;
    while(t--)
    solve();
}
View Code
复制代码

D之后在补555 不会匹配

posted @   xishuiw  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示