首页 > 其他分享 >2023CCPC题解

2023CCPC题解

时间:2024-04-13 19:45:09浏览次数:21  
标签:int 题解 ...... .... ....... 2023CCPC ..... ........

2023 年第五届河南省 CCPC 大学生程序设计竞赛

Problem A. 小水獭游河南

image-20240413193221510

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string a;
        cin>>a;
        int st[27],ji=0;
        memset(st,0,sizeof(st));
        if(a.size()==1)
        {
            cout<<"NaN"<<endl;
            continue;
        }
        st[a[0]-'a']++;
        for(int i=1;i<a.size();i++)
        {   
            st[a[i]-'a']++;
            for(int j=i,k=a.size()-1;j<a.size();j++,k--)
            {
                if(j>=k)
                {
                    cout<<"HE"<<endl;
                    ji=1;
                    break;
                }
                if(a[j]!=a[k])
                {
                    break;
                }
            }
            if(ji==1)
            break;
            //重点
            if(st[a[i]-'a']>1)
            {
                cout<<"NaN"<<endl;
                break;
            }
        }
    };
    return 0;
}

Problem C. Toxel 与随机数生成器

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s,b="";
    cin>>s;
    for(int i=0;i<500;i++)
    b+=s[i];
    if(s.find(b,1001)==-1)
    {
        cout<<"Yes";
    }else
    {
        cout<<"No";
    }
    return 0;
}

Problem F. Art for Last

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+10],b[n+10],c[n+10],q[n+10];
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n-1;i++)b[i]=a[i+1]-a[i];
    int h=1,t=0,cnt=1;
    for(int i=1;i<=n-1;i++)
    {
        while(t>=h&&b[q[t]]>=b[i])t--;
        q[++t]=i;
        if(q[h]<i-k+2)h++;
        if(i>=k-1)c[cnt++]=b[q[h]];
    }
    //重点
    long long res=1e18;
    for(int i=1;i<=n-k+1;i++)
    {
        res=min(res,(long long)c[i]*(a[i+k-1]-a[i]));
    }
    cout<<res;
    return 0;
}

Problem G. Toxel 与字符画

#include <bits/stdc++.h>
using namespace std;

char big[10][10][9] = {
    {
        "........",
        "........",
        ".0000000",
        ".0.....0",
        ".0.....0",
        ".0.....0",
        ".0.....0",
        ".0.....0",
        ".0000000",
        "........",
    },
    {
        "........",
        "........",
        ".......1",
        ".......1",
        ".......1",
        ".......1",
        ".......1",
        ".......1",
        ".......1",
        "........",
    },
    {
        "........",
        "........",
        ".2222222",
        ".......2",
        ".......2",
        ".2222222",
        ".2......",
        ".2......",
        ".2222222",
        "........",
    },
    {
        "........",
        "........",
        ".3333333",
        ".......3",
        ".......3",
        ".3333333",
        ".......3",
        ".......3",
        ".3333333",
        "........",
    },
    {
        "........",
        "........",
        ".4.....4",
        ".4.....4",
        ".4.....4",
        ".4444444",
        ".......4",
        ".......4",
        ".......4",
        "........",
    },
    {
        "........",
        "........",
        ".5555555",
        ".5......",
        ".5......",
        ".5555555",
        ".......5",
        ".......5",
        ".5555555",
        "........",
    },
    {
        "........",
        "........",
        ".6666666",
        ".6......",
        ".6......",
        ".6666666",
        ".6.....6",
        ".6.....6",
        ".6666666",
        "........",
    },
    {
        "........",
        "........",
        ".7777777",
        ".......7",
        ".......7",
        ".......7",
        ".......7",
        ".......7",
        ".......7",
        "........",
    },
    {
        "........",
        "........",
        ".8888888",
        ".8.....8",
        ".8.....8",
        ".8888888",
        ".8.....8",
        ".8.....8",
        ".8888888",
        "........",
    },
    {
        "........",
        "........",
        ".9999999",
        ".9.....9",
        ".9.....9",
        ".9999999",
        ".......9",
        ".......9",
        ".9999999",
        "........",
    },
};

char sml[10][10][7] = {
    {
        "......",
        ".00000",
        ".0...0",
        ".0...0",
        ".0...0",
        ".00000",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".....1",
        ".....1",
        ".....1",
        ".....1",
        ".....1",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".22222",
        ".....2",
        ".22222",
        ".2....",
        ".22222",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".33333",
        ".....3",
        ".33333",
        ".....3",
        ".33333",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".4...4",
        ".4...4",
        ".44444",
        ".....4",
        ".....4",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".55555",
        ".5....",
        ".55555",
        ".....5",
        ".55555",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".66666",
        ".6....",
        ".66666",
        ".6...6",
        ".66666",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".77777",
        ".....7",
        ".....7",
        ".....7",
        ".....7",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".88888",
        ".8...8",
        ".88888",
        ".8...8",
        ".88888",
        "......",
        "......",
        "......",
        "......",
    },
    {
        "......",
        ".99999",
        ".9...9",
        ".99999",
        ".....9",
        ".99999",
        "......",
        "......",
        "......",
        "......",
    },

};

char inf[10][25] = {
    "........................",
    "........................",
    ".IIIIIII.N.....N.FFFFFFF",
    "....I....NN....N.F......",
    "....I....N.N...N.F......",
    "....I....N..N..N.FFFFFFF",
    "....I....N...N.N.F......",
    "....I....N....NN.F......",
    ".IIIIIII.N.....N.F......",
    "........................",
};

char den[10][9]{
    "........",
    "........",
    "........",
    "........",
    ".=======",
    "........",
    ".=======",
    "........",
    "........",
    "........",
};

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        vector<int> a,b,c;
        string m[50];
        long long x,y;
        scanf("%lld^{%lld}",&x,&y);
        long long tx,ty;
        tx=x,ty=y;
        while(tx)
        {
            a.push_back(tx%10);
            tx/=10;
        };
        while(ty)
        {
            b.push_back(ty%10);
            ty/=10;
        };
        reverse(a.begin(),a.end());
        reverse(b.begin(),b.end());
        for(int i=0;i<10;i++)
        {
            for(auto k:a)
            m[i]+=big[k][i];
            for(auto k:b)
            m[i]+=sml[k][i];
            m[i]+=den[i];
        }
        __int128 ans=1;
        int ji=0;
        //重点
        if(x!=1)
        {
         for(long long i=1;i<=y;i++)
        {
            ans*=x;
            if(ans>1e18)
            {
                ji=1;
                break;
            }
        }   
        }
        if(ji)
        {
            for(int i=0;i<10;i++)
            m[i]+=inf[i];
        }else
        {
            while(ans)
            {
                c.push_back(ans%10);
                ans/=10;
            }
            reverse(c.begin(),c.end());
            for(int i=0;i<10;i++)
            {
                for(auto k:c)
                m[i]+=big[k][i];
            }
        }
        for(int i=0;i<10;i++)m[i]+=".";
        for(int i=0;i<10;i++)cout<<m[i]<<endl;
    };
    return 0;
}

Problem H. Travel Begins

#include <bits/stdc++.h>
using namespace std;

int check(double x)
{
    return x-int(x)>=0.5?1:0;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        double t=0.000000000001;
        int n,k,num,ma,mi;
        cin>>n>>k;
        if(2*n>k)
        num=k-1;
        else
        num=2*n;
        ma=num+int(n-0.5*num)+check(n-0.5*num);
        if(2*n==k)
        num=2*n-1;
        mi=int(n-(0.5-t)*num)+check(n-(0.5-t)*num);
        cout<<mi<<" "<<ma<<endl;
    }
    return 0;
}

标签:int,题解,......,....,.......,2023CCPC,.....,........
From: https://www.cnblogs.com/ckeri/p/18133276

相关文章

  • CF1946B Maximum Sum 题解
    题目简述你有一个由$n$个整数组成的数组$a$。你要对它进行$k$次操作。在一次操作中,你选择了数组$a$的任意连续子数组(可能为空),并在数组的任意位置插入了该子数组的和。你的任务是找出经过$k$次操作后数组的最大和。题目分析这道题显然是一道贪心题。对于第$1$次操......
  • 集合计数——题解
    题目这篇题解的背景。。。(可以跳过,与题目无关)说实话,有点恼,也觉得自己有点唐,在以为自己已经理解了变量意义的情况下(实际上并没有)去推了半天错式子,甚至我推出了他不对时还给自己否定了,昨天晚三还拉着\(9G\)与我一块推。。。,结果上午发觉好像意义理解错了。。。抽象,就当是一种......
  • CF416E 题解
    前置知识:floyd题意给定一个\(n\)个点\(m\)条边的无向简单图,对于每对\((s,t),1\les<t\len\),求出有多少条边被至少一个\(s\tot\)的路径经过。\(n\le500,m\le\frac{n(n-1)}{2}\)题解首先一个很一眼的做法先floyd一遍求出\(dis(i,j)\),接着枚举\((s,......
  • [CF1954] Educational Codeforces Round 164 (Rated for Div. 2) 题解
    [CF1954]EducationalCodeforcesRound164(RatedforDiv.2)题解A.PaintingtheRibbon最优策略是染\(\lceil\dfrac{n}{m}\rceil\)个颜色,然后Bob会把剩下的都染成这个颜色voidwork(){intn,m,k,c;cin>>n>>m>>k;c=(n+m-1)/m;......
  • CF1618G Trader Problem 题解
    CF1618GTraderProblem题解题目链接:CF|洛谷提供一个在线做法。分析1我们不妨把\(a\)和\(b\)合并为一个序列,称合并后的序列为\(c\),并将其不降序排序。把玩样例后不难发现:对于一个物品序列\(c_1,c_2,\cdots,c_l\),满足\(\foralli<l,c_{i+1}-c_i\lek\)(即任意......
  • [CF1942] CodeTON Round 8 (Div. 1 + Div. 2, Rated, Prizes! A~E 题解
    [CF1942]CodeTONRound8(Div.1+Div.2,Rated,Prizes!A~E题解A.FarmerJohn'sChallenge只有两种情况,一种是单调递增,这时\(k=1\),另一种是所有数都相同,这时\(k=n\)。B.BessieandMEX首位可以确定,然后从前往后增量构造\(p\)即可。voidwork(){cin>>......
  • CF1837E Play Fixing 题解
    首先来考虑什么情况方案数为\(0\):可以确定,在某一层中,两个原本都能晋级的队伍比赛;可以确定,在某一层中,两个原本都不能晋级的队伍比赛。发现假如写出每一场比赛及其胜者,可以形成一棵树形结构,在里面打标记即可判断是否为\(0\)。我们设\(a_i\)表示第\(i\)层新加的队伍中位......
  • [题解][2022年江西省大学生程序设计竞赛] Remove and append
    题目描述给定一个包含n个整数的数组a。定义一个操作如下:从数组a中选择k个整数,将它们删除,并将它们的和追加到数组末尾。如果数组A比数组B(长度相同)字典序大,那么在A和B第一次不同的位置上,A的数字比B对应位置上的数字要大。例如,[0,1,14,0]比[0,1,5,6]字典序大,因为它们在第三......
  • C++算法题解 - 递归实现排列型枚举 - 递归法 (图文) (递归搜索树)
    题目:递归实现排列型枚举把1∼n这n个整数排成一行后随机打乱顺序,输出所有可能的次序。输入格式一个整数n。输出格式按照从小到大的顺序输出所有方案,每行1个。首先,同一行相邻两个数用一个空格隔开。其次,对于两个不同的行,对应下标的数一一比较,字典序较小的排在前面。数据......
  • [题解] [洛谷P7883] 平面最近点对(加强版)
    [洛谷P1429]平面最近点对(加强版)题目描述给定平面上的\(n\)个点,求其中距离最小的两个点之间的距离。输入格式第一行:\(n\),保证\(2\leqn\leq200000\)。接下来\(n\)行,每行两个实数:\(x,y\),表示一个点的横坐标和纵坐标,中间用一个空格隔开。输出格式仅一行,一个实数......