2022河南萌新联赛第(六)场:郑州大学 (ACDFHKL)

https://ac.nowcoder.com/acm/contest/39114

C 盲打(模拟)

  • 大写的时候就多个shift键就🆗
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const LL N=200200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    map<char,PII> mp;
    mp['q']={1,1}; mp['w']={1,2}; mp['e']={1,3}; mp['r']={1,4}; mp['t']={1,5}; mp['y']={1,6}; mp['u']={1,7}; mp['i']={1,8}; mp['o']={1,9}; mp['p']={1,10};
    mp['a']={2,1}; mp['s']={2,2}; mp['d']={2,3}; mp['f']={2,4}; mp['g']={2,5}; mp['h']={2,6}; mp['j']={2,7}; mp['k']={2,8}; mp['l']={2,9};
    mp['z']={3,2}; mp['x']={3,3}; mp['c']={3,4}; mp['v']={3,5}; mp['b']={3,6}; mp['n']={3,7}; mp['m']={3,8};
    int T=1;
    cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]>='a'&&s[i]<='z') cout<<mp[s[i]].first<<" "<<mp[s[i]].second<<endl;
            else
            {
                cout<<"3 1 ";
                cout<<mp[s[i]+32].first<<" "<<mp[s[i]+32].second<<endl;
            }
        }
    }
    return 0;
}

H 数列求和(斐波那契数列改造)

  • 把数组开大一点儿就odk
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL N=20020000,M=2002;
const LL mod=1e11+3;
LL f[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    LL sum=0;
    for(LL i=1;i<=n;i++)
    {
        if(i==1) f[i]=1;
        else if(i==2) f[i]=3;
        else f[i]=(f[i-1]%mod+f[i-2]%mod)%mod;
        //cout<<f[i]<<" ";
        sum+=f[i]%mod;
    }
    cout<<sum%mod<<endl;
    return 0;
}

L 字符串

  • 问我们从前面移动一些字母到后面,使之成为原串的可能性有多少?
  • 这个题目我们可以通过模拟得知:我们将要移动到后面的字母必须要和移动后的前面的字母一模一样,也必须和未移动前的字母一模一样
  • 同理可知,我们取的前x个字母,后面x,x,x都必须与x+1,x+1,x+1一样
  • 所以这个题目就转化成了求字符串的最短可组成的长度
  • 这样在这个长度的倍数下,无论怎么移动都是可以恢复成原串了
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const LL N=200200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s,c;
    cin>>s;
    int idx=0;
    while(1)
    {
        c+=s[idx];
        if(n%c.size()) ;
        else{
        bool flag=true;
        for(int i=0;i<n;i+=(idx+1))
        {
            if(s.substr(i,idx+1)!=c)
            {
                flag=false;
                break;
            }
        }
        if(flag==true) break;
        }
        idx++;
    }
    //cout<<c<<endl;
    if(c==s) cout<<"1"<<endl;
    else cout<<n/c.size()<<endl;
    return 0;
}

F 取石子,但是作弊

  • 典型博弈论:NIM游戏

看代码有详解
Acwing基础课博弈论知识链接:https://www.acwing.com/blog/content/406/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const LL N=200200,M=2002;
int a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    LL res=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i==1) res=a[1];
        else res^=a[i];
    }
    //只有一堆石子的时候,必然输
    if(n==1)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    //a1∧a2∧⋯∧an=0时先手必败,否则先手必胜
    if(res==0)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    else
    {
        if(a[1]==1)
        {
            cout<<"-1"<<endl;
            return 0;
        }
        else
        {
            for(int num=1;num<a[1];num++)//可以拿走的数量
            {
                for(int i=2;i<=n;i++)
                {
                    //换掉石子使之异或和成为0
                    int flag=res^a[1]^a[i+1]^(a[1]-num)^(a[i+1]+num);
                    if(flag==0)
                    {
                        cout<<num<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

K 魔法数

"魔法数"定义:

  • 该数是正整数
  • 该数的正约数有5个

一个数的约数有五个,那么必定是一个平方数,比如1 2 4 8 16
形如a b c d e
如何才能确保b这里只有一个呢?
也就是c这个平方数只能分解出除了1和它本身之外只有一个数字
只有质数

  • 暴力打表
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200200,M=2002;
vector<LL> v;
LL a[N];
bool is_prime(LL x)
{
    if(x<2) return false;
    for(LL i=2;i<=x/i;i++)
        if(x%i==0) return false;
    return true;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    for(LL i=2;i<=1000;i++)
    {
        if(is_prime(i)==true) v.push_back(i*i*i*i);
    }
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL l,r;
        cin>>l>>r;
        LL sum=0;
        for(LL i=0;i<v.size();i++)
        {
            if(v[i]>=l&&v[i]<=r) sum++;
            if(v[i]>r) break;
        }
        cout<<sum<<endl;
    }
    return 0;
}

A
D
稍后续上

posted @ 2022-08-14 18:29  高尔赛凡尔娟  阅读(48)  评论(0编辑  收藏  举报