本节课标题
得分情况与用时
T1: 100分,用时50分钟
T2: 0分,用时20分钟
T3: 0分,用时15分钟
T4: 60分,用时45分钟
T1
题意
按成绩从高到低蛇形(列间来回,奇数列上到下、偶数列下到上)分配 n 行 m 列座位,给定包含小R成绩的成绩表,输出小R的列号和行号。
思路
两种写法,先排序,第一是模拟这个过程,第二则是数学方法,推导公式,行数等于步数,
代码
#include <bits/stdc++.h>
#define long long int
using namespace std;
struct P {
int s, id;
};
int n, m;
int rx, ry;
int f[3][2]={{1, 0}, {0, 1}, {-1, 0}};
P a[110];
bool cmp (P a1, P a2) {
return a1.s>a2.s;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i=1; i<=n*m; i++) {
cin >> a[i].s;
a[i].id=i;
}
int len=n*m, step=0;
sort (a+1, a+len+1, cmp);
for (int i=1; i<=n*m; i++) {
if (a[i].id==1) {
step=i;
break;
}
}
int c=step/n, r=1, rem=step%n;
if (rem!=0) c++;
else rem=n;
if (c%2==1) {
r=rem;
} else {
r=n-rem+1;
}
cout << c << " " << r;
return 0;
}个人总结
很简单的一个题(不是。。。),直接秒杀(并非),好题多出。
T2
题意
模拟机器人按方向走 k 步(遇障碍或越界则右转不移动),统计包含起点在内机器人实际到达过的不同位置数量。
思路
类似于小田赶牛,循环模拟路径即可
代码
#include<bits/stdc++.h>
using namespace std;
int d[4][2]={0, 1, 1, 0, 0, -1, -1, 0};
int cnt=1;
int rx=1, ry=1, t, n, m, k;
char mp[1005][1005];
bool v[1005][1005];
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
cin >> n >> m >> k;
cnt=1;
int x0, y0, d0;
cin >> x0 >> y0 >> d0;
rx=x0, ry=y0;
int w=d0;
memset(v, 0, sizeof v);
v[x0][y0]=1;
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++) cin >> mp[i][j];
while (k--) {
int nx=rx+d[w][0], ny=ry+d[w][1];
if (nx<1 or nx>n or ny<1 or ny>m or mp[nx][ny]=='x') w=(w+1)%4;
else {
rx=nx, ry=ny;
if (v[nx][ny]==0) {
cnt++;
v[rx][ry]=1;
}
}
}
cout << cnt << '\n';
}
return 0;
}个人总结
题目思路容易想到,但被模拟路径的那里卡住了,写了很久的代码,不知道自己是不是没睡醒。
T3
题意
从底层指定房间出发,每层累加当前房间指示牌数字,然后在该层逆时针找第 x 个有楼梯的房间上楼,重复至顶层,输出累加和对 20123 取模的结果。
思路
暴力模拟能拿50分
满分思路:累加当前房间数字,用当前数字对当前层楼梯总数取模优化步数,然后逆时针找第 step 个有楼梯的房间并更新房间号,重复至顶层。
代码
#include<bits/stdc++.h>
using namespace std;
const int MAXN=10005;
const int MAXM=105;
const int MOD=20123;
struct P {
int f;
int x;
};
P a[MAXN][MAXM];
int cnt[MAXN];
int n, m;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
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;
cin >> t;
int ans=0;
for (int i=1; i<=n; i++) {
ans=(ans+a[i][t].x)%MOD;
int step=a[i][t].x%cnt[i];
if (step==0) step=cnt[i];
while (step) {
if (a[i][t].f) {
step--;
if (step==0) break;
}
t=(t+1)%m;
}
}
cout << ans << '\n';
return 0;
}个人总结
emmm…我确实没睡醒,听了课发现是道很简单的模拟,我早上在干什么啊啊啊啊啊!暴力都能拿50,老师还贴心的加了特殊情况,我愣是一分没捞着呵呵😐,吸取教训下次注意吧
T4
题意
计算 螺旋矩阵中第 i 行第 j 列的值(懒得罗里吧嗦一大堆了。。。)
思路
根据目标位置到四边的最小距离确定所在圈层,累加外层总数后,再根据在该圈的上/右/下/左四条边的位置直接计算出数值(老师讲的是另一种模拟的写法,但我写都写了,还是在原代码的基础上改的)。
代码
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> x >> y;
int layer=min(min(x-1, y-1), min(n-x, n-y));
int len=n-2*layer;
int prev=n*n-len*len;
int ans;
if (x==layer+1) {
ans=prev+(y-layer);
}
else if (y==n-layer) {
ans=prev+len+(x-(layer+1));
}
else if (x==n-layer) {
ans=prev+2*len-1+(n-layer-y);
}
else {
ans=prev+3*len-2+(n-layer-x);
}
cout << ans << '\n';
return 0;
}个人总结
还可以,源代码问题不大,接近正确了,燃了一个小时实在燃尽了,脑子有点死了,莫碰邪修,还是写老师的方法好
整场考试总结
这次考试我觉得在T1花的时间有些太久了,一直在那想什么数学解法。。。 想了半天,现在想想,多留点时间给后面,我T5说不定还能多拿几十分。
感觉对模拟这方面有待加强,菜就要多练啊