day03 比赛复盘总结

· · 个人记录

day03 比赛复盘总结

得分情况与用时

T1:20分

T2:0分

T3:0分

T4:0分

T1题目解析

题意

根据成绩蛇形分配座位,求小 R 的座位。

思路

先排序找到排名,再根据蛇形排列规律计算位置。

AC代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[105];
bool cmp(int a,int b)
{
    return a>b;
}
signed main()
{
    int n,m;
    cin>>n>>m;
    cin>>a[1];
    int s=a[1]; 
    for(int i=2;i<=n*m;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n*m,cmp);
    int cnt;
    for(int i=1;i<=n*m;i++)
    {
        if(a[i]==s)cnt=i-1;
    } 
    int k=cnt;
    int x=1,y=1,w=1;
    while(k--)
    {
        if(w==1)
        {
            x++;
            if(x==n+1)x=n,y++,w=0;
        }
        else
        {
            x--;
            if(x==0)x=1,y++,w=1;
        }
    } 
    cout<<y<<" "<<x;
    return 0;
}

个人总结

没看清最后要求先输出列再输出行

T2题目解析

题意

模拟机器人移动,求经过的不同位置数量。

思路

直接模拟,最后记录经过的点的数量

AC代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k;
int x,y,d;
char a[1005][1005];
bool vis[1005][1005];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int ans=1;
bool check(int x,int y)
{
    return (x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]!='x');
}
signed main()
{
    int T;
    cin>>T;
    while(T--)
    {
        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--)
        {
            int nx=x+dx[d];
            int ny=y+dy[d];
            if(!check(nx,ny))d=(d+1)%4;
            else
            {
                x=nx,y=ny;
                vis[x][y]=1;
            }
        }
        ans=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(vis[i][j]==1)ans++;
                vis[i][j]=0;
            }
        }
        cout<<ans<<endl;
    } 
    return 0;
}

个人总结

这道题看题面直接写到深搜去了

T3题目解析

题意

根据房间信息寻找楼梯,求经过房间数字的总和。

思路

用结构体存储房间信息,模拟每层移动过程,并用取模优化寻找楼梯。

AC代码

#include <bits/stdc++.h>
#define int long long
#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int N = 1e4+5, M = 1e2+5, mod = 20123;
struct P 
{
    int f, x; 
};
int n, m, cnt[N]; 
P a[N][M];
signed main() 
{
    qwq;
    cin >> n >> m;
    for (int i=1; i<=n; i++) 
    {
        for (int j=0; j<m; j++) 
        {
            cin >> a[i][j].f >> a[i][j].x;
            cnt[i] += a[i][j].f;
        }
    }
    int t, res = 0;
    cin >> t;
    for (int i=1; i<=n; i++) 
    {
        res = (res + a[i][t].x) % mod;
        int k = a[i][t].x % cnt[i];
        if (k == 0) k = cnt[i];
        while (k) 
        {
            if (a[i][t].f) k--;
            if (k == 0) break;
            t = (t+1) % m;
        }
    }
    cout << res;
    return 0;
}

个人总结

这道题因为前面死磕T2去了没做

T4题目解析

题意

求螺旋矩阵中指定位置的数字。

思路

看是在哪一层然后模拟

AC代码

#include <bits/stdc++.h>
using namespace std;
int q = 1;
int n, i, j, x, y;
int nd = 0;
int d[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
int main() 
{
    cin >> n >> i >> j;
    int v = min({i, j, n-i+1, n-j+1})-1;
    q = n*n - (n-2*v)*(n-2*v)+1;
    x = v+1, y = v+1;
    while (i != x or j != y) 
    {
        q++;
        int nx = x+d[nd][0], ny = y+d[nd][1];
        if (nx < v+1 or nx > n-v or ny < v+1 or ny > n-v) 
        {
            nd = (nd+1) % 4;
            nx = x+d[nd][0], ny = y+d[nd][1];
        }
        x = nx, y = ny;
    }
    cout << q;
    return 0;
}

个人总结

这道题没时间做了

整场考试总结

这次考试时间还是把握不好,我没有把所有题目的题面都看完,所以后来老师讲题的时候还是会有一点跟不上

代码能力还要增强