牛客小白月赛59 ABCDEF

C E F 题目质量挺高的
https://ac.nowcoder.com/acm/contest/43844/A

A-我会开摆

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
char a[M][M];
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        for(int i=1;i<=4;i++)
        {
            for(int j=1;j<=4;j++)
            {
                cin>>a[i][j];
            }
        }
        bool flag=false;
        for(int i=1;i<=3;i++)
        {
            for(int j=1;j<=3;j++)
            {
                if(a[i][j]==a[i+1][j]&&a[i][j]==a[i][j+1]&&a[i][j]==a[i+1][j+1])
                {
                    flag=true;
                    break;
                }
            }
        }
        if(flag==false) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

https://ac.nowcoder.com/acm/contest/43844/B

B-走廊的灯

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL f[N];
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        LL maxn=0;
        LL sum=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='0'||s[i]=='2') sum++;
            else if(s[i]=='1') sum=0;
            maxn=max(maxn,sum);
        }
        sum=0;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='1'||s[i]=='2') sum++;
            else if(s[i]=='0') sum=0;
            maxn=max(maxn,sum);
        }
        cout<<maxn<<endl;
    }
    return 0;
}

https://ac.nowcoder.com/acm/contest/43844/C

C-输出练习

输入
4
1 10 2
2 4 5
19562 31702689720 17701
3680 37745933600 10
输出
1 2 4 8 
None.
313325401 
10000 100000 1000000 10000000 100000000 1000000000 10000000000

可以用这么暴力的方法我是没有想到的
一整个吃惊😮大动作

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL l,r,k;
        cin>>l>>r>>k;
        bool flag=false;
        if(k==0&&l==0)
        {
            cout<<"0 ";
            flag=true;
        }
        LL x=1;
        while(x<=r)
        {
            if(x>=l&&x<=r)
            {
                cout<<x<<" ";
                flag=true;
            }
            if(k==1||k==0) break;
            if(x>r/k) break; //注意这里要写除法,过大的乘法会爆
            x*=k;
        }
        if(flag==false) cout<<"None."<<endl;
        else cout<<endl;
    }
    return 0;
}

https://ac.nowcoder.com/acm/contest/43844/D

D-国际象棋

一把过了这题,感觉我可以培养一下,没准成了一个大模拟选手(哈哈(傻笑

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL n,m,k,t;
LL a[M][M];
vector<LL> v[N];
//LL dx[]={-1,0,0,1,-1,-1,1,1},dy[]={0,1,-1,0,1,-1,1,-1};
bool check(LL x,LL y,LL idx)
{
    //横
    LL hen=0;
    for(int i=y;i>=1;i--)
    {
        if(a[x][i]==idx) hen++;
        else break;
    }
    for(int i=y+1;i<=m;i++)
    {
        if(a[x][i]==idx) hen++;
        else break;
    }
    if(hen>=k) return true;
    //竖
    LL shu=0;
    for(int i=x;i>=1;i--)
    {
        if(a[i][y]==idx) shu++;
        else break;
    }
    for(int i=x+1;i<=m;i++)
    {
        if(a[i][y]==idx) shu++;
        else break;
    }
    if(shu>=k) return true;
    //主对角线
    LL zhu=0;
    for(int i=x,j=y;i>=1&&j>=1;i--,j--)
    {
        if(a[i][j]==idx) zhu++;
        else break;
    }
    for(int i=x+1,j=y+1;i<=n&&j<=m;i++,j++)
    {
        if(a[i][j]==idx) zhu++;
        else break;
    }
    if(zhu>=k) return true;
    //副对角线
    LL fu=0;
    for(int i=x,j=y;i>=1&&j<=m;i--,j++)
    {
        if(a[i][j]==idx) fu++;
        else break;
    }
    for(int i=x+1,j=y-1;i<=n&&j>=1;i++,j--)
    {
        if(a[i][j]==idx) fu++;
        else break;
    }
    if(fu>=k) return true;
    return false;
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n>>m>>k>>t;
        memset(a,0,sizeof a);
        for(int i=1;i<=t;i++)
        {
            LL x;
            cin>>x;
            v[x].push_back(1);//奇数次落子时这颗子是黑棋,否则是白棋
            if(i%2==1)
            {
                a[n-v[x].size()+1][x]=1;//黑色
                if(check(n-v[x].size()+1,x,1)==true) break;
            }
            else
            {
                a[n-v[x].size()+1][x]=2;//白色
                if(check(n-v[x].size()+1,x,2)==true) break;
            }
        }
        LL sum=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(a[i][j]!=0) sum++;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

https://ac.nowcoder.com/acm/contest/43844/E

E-弹珠碰撞

输入 
2 2
0 1
1 2
输出 
1
示例2
输入 
3 2
1 0
1 3
输出 
4

这题和蓝桥杯有个蚂蚁🐜的感觉相似度99%,然而这并不妨碍我读题半小时+

代码极其优美,值得揣摩

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL n,m;
LL d[N],p[N],to[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n>>m;
        for(int i=1;i<=m;i++)
        {
            cin>>d[i];//小球指向
        }
        for(int i=1;i<=m;i++)
        {
            cin>>p[i];//小球位置
            //0表示没有小球
            //1表示有小球,指向了左边
            //2表示有小球,指向了右边
            to[p[i]]=d[i]+1;//小球的位置以及朝向
        }
        LL l=0,r=0,ans=0;
        for(int i=1;i<=n;i++)
        {
            if(to[i]==0) continue;
            if(to[i]==1) ans=max(ans,i+r);//如果有向左的小球,答案就是和当前位置和向右(左边来的)的相加取最大
            else r++;//如果有向右的小球,个数++
        }
        for(int i=n;i;i--)
        {
            if(to[i]==0) continue;
            //n-i+1表示的就是n到i的位置的数量
            if(to[i]==2) ans=max(ans,n+1-i+l);//如果有向右的小球,答案就是和当前位置和向左(右边来的)的相加取最大
            else l++;//如果有向左的小球,个数++
        }
        cout<<ans<<endl;
    }
    return 0;
}

https://ac.nowcoder.com/acm/contest/43844/F

F-困难卷积

输入
4
1 2 3 4
2 3 3 3
输出
12

mp的神奇用法,根据数据范围进行压缩

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL n;
//<key, value>
map<LL,LL> a,b;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        {
            LL x;
            cin>>x;
            a[x]++;
        }
        for(int i=0;i<n;i++)
        {
            LL x;
            cin>>x;
            b[x]++;
        }
        LL ans=0;
        //i,j是遍历到的key
        //x,y是value
        for(auto [i,x]:a)
        {
            for(auto [j,y]:b)
            {
                //i,j是值,x,y是个数
                ans+=(int)sqrt(abs(i-j))*x*y;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
posted @ 2023-03-31 19:56  高尔赛凡尔娟  阅读(17)  评论(0编辑  收藏  举报