Codeforces Round 937 (Div. 4)( 6 / 7)

文章包含了五个编程问题,涉及排序判断(A-Stair,Peak,None)、字符串模式生成(Upscaling)、时间转换(ClockConversion)、二进制数字乘积检查(ProductofBinaryDecimals)以及最短重复子串查找(NearlyShortestRepeatingSubstring)。每个问题展示了不同的C++编程技巧和逻辑处理。
摘要由CSDN通过智能技术生成

A - Stair, Peak, or Neither?

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b&&b<c)cout<<"STAIR"<<endl;
    else if(a<b&&b>c)cout<<"PEAK"<<endl;
    else cout<<"NONE"<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

B - Upscaling

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n;
    cin>>n;
    string s1,s2;
    for(int i=1;i<=n;i++){
        if(i&1)s1+="##",s2+="..";
        else s1+="..",s2+="##";
    }
    for(int i=1;i<=n;i++){
        if(i&1)cout<<s1<<endl<<s1<<endl;
        else cout<<s2<<endl<<s2<<endl;
    }
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

C - Clock Conversion

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int h,m;
    char c;
    string s;
    cin>>s;
    stringstream iss(s);
    iss>>h>>c>>m;
    int h1=(h+11)%12+1;
    s[0]=h1/10+'0';
    s[1]=h1%10+'0';
    cout<<s<<' '<<(h<12?"AM":"PM")<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

D - Product of Binary Decimals

#include<bits/stdc++.h>
using namespace std;
bool check(int i){
    while(i){
        if(i%10>1)return false;
        i/=10;
    }
    return true;
}
set<int>a;
vector<int>v;
void init(){
    for(int i=1;i<=1e5;i++)
        if(check(i))v.push_back(i);
    for(int m:v){
        for(int n:v){
            if(n==1)continue;
            int sum=m*n;
            while(sum<=1e5){
                a.insert(sum);
                sum*=n;
            }
        }
    }
    a.insert(1);
}
void solve(){
    int q;
    cin>>q;
    if(a.count(q))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    init();
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

E - Nearly Shortest Repeating Substring

#include<bits/stdc++.h>
using namespace std;
void solve(){
    string s;
    int n;
    cin>>n>>s;
    for(int i=1;i<=n;i++){
        if(n%i!=0)continue;
        string s1=s.substr(0,i);
        string s2=s.substr(n-i);
        string a,b;
        for(int j=0;j<n/i;j++){
            a+=s1,b+=s2;
        }
        int ans1=0,ans2=0;
        for(int i=0;i<n;i++){
            ans1+=(a[i]!=s[i]);
            ans2+=(b[i]!=s[i]);
        }
        if(min(ans1,ans2)<2){cout<<i<<endl;return ;}
    }
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

F - 0, 1, 2, Tree!

#include<bits/stdc++.h>
using namespace std;
void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+1!=c)cout<<"-1"<<endl;
    else{
        int v=1;
        int ans=0;
        while(v<=a){
            v*=2;
            ans++;
        }
        int k=v-1-a;
        if(b>k)ans+=(b-k+c-1)/c;
        cout<<ans<<endl;
    }
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--)solve();
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值