第五届CCPC河南省省赛部分题解+心得

心得:

        2023.5.7有幸通过学校提供的支持和帮助来到郑州轻工业大学(我轻)参加第五届CCPC河南省省赛,作为大一,心中也是无比激动和喜悦,更希望能在这次比赛中拿到奖!(喜拿铜)

A-  小水獭游河南

        按照题目要求 字符串s当且仅当存在两个非空字符串a,b
        (1)a字符串中每种字母只出现一次    (2)b是一个回文串    (3)s=a+b

思路:最多枚举前26个字母 判断前字符串有无重复字母出现 后字符串是否为回文串

         因为a b都是非空 因此长度小于2的不要忘记特判一下即可

      

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long

int n,m;
string str;

void solve()
{
    map<char,int> ma;
    cin>>str;
    int l=str.size();
    if(l<2)
    {
        cout<<"NaN\n";
        return ;
    }

    for(int i=0;i<l;i++)
    {
        ma[str[i]]++;
        if(ma[str[i]]>=2)
        {
            cout<<"NaN\n";
            return ;
        }
        string res=str.substr(i+1);
        string ans=res;
        reverse(ans.begin(),ans.end());
        if(ans==res)
        {
            cout<<"HE\n";
            return ;
        }
    }
}

signed main()
{
    IOS
    int T=1;
    cin>>T;
    while(T--) solve();
    
    return 0;
}

C-Toxel 与随机数生成器

诈骗题 题目说一大堆 但有用的就那几行(理解让做什么 就会变得很简单

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long

int n,m;
string str;

void solve()
{
    cin>>str;
    string res=str.substr(0,1000);
    if(str.find(res,1)!=-1)cout<<"No\n";
    else cout<<"Yes\n";
}

signed main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--) solve();
    
    return 0;
}

F-Art for Last 

在n个数中选取k个数 使得k个数中(任意2个数之差的最小值)乘 (任意2数的之差最大值) 的 值最小 

可以先将原数组进行排序 这样在k个数中任意2个数之差的最小值 即为相邻的两个数差值 最大值 即为 k个数中第一个和最后一个差值(因为已排序

再利用滑动窗口 维护求出最小值

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long

const int N=5e5+10;
int n,k;
string str;
int a[N],b[N],q[N];

void solve()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<n;i++)b[i]=a[i+1]-a[i];

    int ans=0x3f3f3f3f3f3f3f3f;//long long
    int hh=0,tt=-1;
    for(int i=1;i<=n;i++)
    {
        if(tt>=hh&&i-k+1>q[hh])hh++;
        while(tt>=hh&&b[q[tt]]>=b[i])tt--;
        if(i>=k)
        {
            int res=b[q[hh]]*(a[i]-a[i-k+1]);
            ans=min(ans,res);
        }
        q[++tt]=i;
    }
    cout<<ans<<"\n";
}

signed main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--) solve();
    
    return 0;
}

H-Travel Begins

比赛时没推的这么牛 把推的所有情况都总和起来 来勉强过了

(1)2*n<k的情况下 把每份都分成小于0.5的值 min最小为0 

                把能分的0.5都分出去 不够的用0 max=2*n

 (2) 2*n>=k的情况下 把k-1都分成0.49999...... 最后一个分成剩余的数

                把k-1分成0.5 最后一个分成剩余的数

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int n,k;
string str;

void solve()
{
    cin>>n>>k;
    if(2*n<k)cout<<0<<" "<<2*n<<"\n";
    else cout<<n-(k-1)/2<<" "<<n+k/2<<"\n";
}

int main()
{
    IOS
    int T=1;
    cin>>T;
    while(T--) solve();
    
    return 0;
}

K-排列与质数

(n<=4)无法构成

(n<=10)通过暴力枚举求解

(n>10)奇:按1.3.5...n-2.n.n-3.n-5....8,6,4   //发现一定有解 2放到5.7之间

                偶:按1.3.5...n-3.n.n-2.n-4.....8,6,4 // n-1放到n-4和n-6之间

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int n;

void solve()
{
    cin>>n;
    if(n<=4)
    {
        cout<<"-1\n";
        return ;
    }
    if(n==5)cout<<"4 1 3 5 2\n";
    if(n==6)cout<<"2 4 6 1 3 5\n";
    if(n==7)cout<<"2 4 6 1 3 5 7\n";
    if(n==8)cout<<"2 4 6 8 1 3 5 7\n";
    if(n==9)cout<<"2 4 6 8 1 3 5 7 9\n";
    if(n==10)cout<<"2 4 1 6 3 5 8 10 7 9\n";
    if(n==11)cout << "1 3 10 5 2 7 9 11 8 6 4\n";
    if(n>11)
    {
        if(n&1)
        {
            for(int i=1;i<=n;i+=2)
            {
                cout<<i<<" ";
                if(i==5)cout<<"2 ";
                if(i==n-6)cout<<n-1<<" ";
            }
            for(int i=n-3;i>=4;i-=2)
                cout<<i<<" ";
        }
        else
        {
            for(int i=1;i<=n-3;i+=2)
            {
                cout<<i<<" ";
                if(i==5)cout<<"2 ";
            }
            for(int i=n;i>=4;i-=2)
            {
                cout<<i<<" ";
                if(i==n-4)cout<<n-1<<" ";
            }
        }
    }
}

signed main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--) solve();
    
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值