8.8日CSP-J 2024年真题考试

· · 个人记录

用时与得分

T1:用时10分钟,得分$$

T2:用时40分钟,得分$$

T3:用时40分钟,得分$$

T4:用时20分钟,得分$$

T1题目解析

题意

给定n张扑克牌,问你除了大王小王还少了几张牌?

思路

直接用map统计出现次数减去52即可

思路

#include<bits/stdc++.h>
#define ll long long
using namespace std;
string s;
ll n;
map<string,ll> mp;
signed main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    ll len=mp.size();
    cout<<52-len;
    return 0;
}

个人总结

秒杀,热身题

T2题目解析

题意

给定义一个机器人的初始位置(x,y)和初始方向d和k此操纵机器人的机会,问你机器人总共走过了几个格子?

思路

这一题看着是一道DFS,但是它其实是一道模拟

首先题目是给了我们k次操纵机器人的机会,所以肯定是while(k--),每次的操纵

先用方向数组确定机器人的下一步位置,在判断位置是否出界是否是障碍是就需要调整方向变量d转弯,不是就标记哦我们呢做过的路,更新一下此时的位置即可

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll T;
const int N=1e3+5;
ll n,m,k;
ll x,y,d;
char a[N][N];
ll vis[N][N];
ll dis[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
void solve()
{
    memset(vis,0,sizeof vis);
    ll sum=0;
    cin>>n>>m>>k;
    cin>>x>>y>>d;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    vis[x][y]=1;
    while(k--)
    {
        ll nx=x+dis[d][0];
        ll ny=y+dis[d][1];
        if(nx<=n && ny<=m && nx>0 && ny>0 && a[nx][ny]=='.')
        {
            vis[nx][ny]=1;
            x=nx;
            y=ny;   
        }
        else d=(d+1)%4;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            sum+=vis[i][j];
        }
    }
    cout<<sum<<'\n';
}
signed main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>T;
    while(T--) solve();
    return 0;
}

个人总结

首先看到这题想到了DFS,但是细看题目又觉得是模拟,结果真是模拟。。。

很简单的模拟,模拟思路可以根据类似迷宫DFS去做,结果我文件名多加了一个空格,痛失100分🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯

T3题目解析

题目解析

有n根木棍,问你这些木棍能组成的最小数字是什么?

思路

优先用消耗火柴最多的数字8凑最多位数,位数越少数越小,对n \%7得到的余数分类处理开头最小数字。

余数特殊情况直接输出对应前缀,剩余火柴全部输出8,n=1无解直接输出-1。

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll T;
ll n;
void solve()
{
    cin>>n;
    if(n==1)
    {
        cout<<-1<<'\n';
        return ;
    }
    if(n<7)
    {
        if(n==2) cout<<1<<'\n';
        if(n==3) cout<<7<<'\n';
        if(n==4) cout<<4<<'\n';
        if(n==5) cout<<2<<'\n';
        if(n==6) cout<<6<<'\n';
        return ;
    }
    ll r=n%7,cnt=n/7;
    if(r==1)
    {
        cout<<10;
        cnt--;
    }
    if(r==2) cout<<1;
    if(r==3)
    {
        if(cnt==1)
        {
            cout<<22;
            cnt--;
        }
        else
        {
            cout<<200;
            cnt-=2;
        }
    }
    if(r==4)
    {
        cout<<20;
        cnt--;
    }
    if(r==5) cout<<2;
    if(r==6) cout<<6;
    while(cnt--) cout<<8;
    cout<<'\n';
}
signed main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>T;
    while(T--) solve();
    return 0;
}
```#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll T;
ll n;
void solve()
{
    cin>>n;
    if(n==1)
    {
        cout<<-1<<'\n';
        return ;
    }
    if(n<7)
    {
        if(n==2) cout<<1<<'\n';
        if(n==3) cout<<7<<'\n';
        if(n==4) cout<<4<<'\n';
        if(n==5) cout<<2<<'\n';
        if(n==6) cout<<6<<'\n';
        return ;
    }
    ll r=n%7,cnt=n/7;
    if(r==1)
    {
        cout<<10;
        cnt--;
    }
    if(r==2) cout<<1;
    if(r==3)
    {
        if(cnt==1)
        {
            cout<<22;
            cnt--;
        }
        else
        {
            cout<<200;
            cnt-=2;
        }
    }
    if(r==4)
    {
        cout<<20;
        cnt--;
    }
    if(r==5) cout<<2;
    if(r==6) cout<<6;
    while(cnt--) cout<<8;
    cout<<'\n';
}
signed main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>T;
    while(T--) solve();
    return 0;
}

个人总结

666没有换行,痛失60分,🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯🤯