跳到正文

个人记录

张友帆8月24日总结

xiaoxiaofan约 13 分钟
原文
文章信息与版本

文章信息

发布
2026年8月24日
收录
2026年8月24日
更新
2026年11月21日
篇幅
约 13 分钟
获赞
1

版本

  1. v6当前
  2. v5
  3. v4
  4. v3
更早的 2 个版本
  1. v2
  2. v1

一、比赛基本情况

比赛日期:8月24日 比赛时长:2h 比赛得分:105分 比赛排名:1

二、比赛整体回顾

简要记录本场比赛的做题顺序、时间安排、比赛状态以及整体感受。 感觉整体来说,还是比较难的,需要动脑。

三、题目复盘

T1:优秀的拆分

本题得分:55分 开始时间:2:00 结束时间:2:45 总用时:45分

初始思路

记录看到题目后的第一反应、观察到的性质,以及最初准备采用的解法。 第一反应就是打表,观察到数量不能相同,直接while循环来解。

考场解题过程

记录考场上思路的发展、调整和最终采用的做法。 用打表。

考场代码

// 在此粘贴考场代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e6 + 5;

int n, a[MAXN], mini = 2, xiabiao, b[MAXN], cnt = 0;                               

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("power.in", "r", stdin);
	//freopen("power.out", "w", stdout);
	cin >> n;
	a[1] = 2;
	for(int i = 2; pow(2, i) < n; i ++){
		a[i] = pow(2, i);
		if(n - mini > n - a[i]){
			mini = a[i];
			xiabiao = i;
		}
	}
    n -= mini;
    cnt ++;
    b[cnt] = mini;
	while(n != 0){
		for(int i = xiabiao - 1; i >= 1; i --){
			if(n - a[i] >= 0){
				cnt ++;
				b[cnt] = a[i];
				n -= a[i];
				xiabiao = i;
				break;
			}
		}
		if(xiabiao == 1){
			break;
		}
	}
	if(n > 0){
		cout << -1;
		return 0;
	}
	for(int i = 1; i <= cnt; i ++){
		cout << b[i] << " "; 
	}
	return 0;
} 

赛后题解

用自己的语言整理本题的正确思路、关键结论和算法流程。 开始先判断n是不是奇数,如果是就输出-1,return 0;否则,可以用从大到小的循环30到1,因为从小到大的情况,大的就不好处理了,然后看一下能不能被减去,如果能就要输出2的i次方,并且n要减去2的i次方。

补题代码

// 在此粘贴考场代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1000005;
int n; 
signed main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin >> n;
    if(n % 2 == 1){
    	cout << -1;
    	return 0;
	}
    for(int i = 30; i >= 1; i --){
    	int cnt = 1;
    	for(int j = 1; j <= i; j ++){
    		cnt *= 2;
		}
    	if(n - cnt >= 0){
    		cout << cnt << " ";
    		n -= cnt;
		}
	}
	return 0;
}

复杂度

时间复杂度:30 空间复杂度: 本题总结 记录本题出现的问题、值得保留的做法以及赛后的主要收获。 不要把问题想的太复杂。

T2:直播获奖

本题得分:50分 开始时间:2:46 结束时间:3:32 总用时:46分

初始思路

考场解题过程

考场代码

// 在此粘贴考场代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e6 + 5;

int n, a[MAXN], pos[MAXN];
double w;

struct Node{
	int val;
	bool operator < (Node b)const{
		return val < b.val;
	}
};
priority_queue<Node> pq;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("live.in", "r", stdin);
	//freopen("live.out", "w", stdout);
	cin >> n >> w;
	w = w / 100;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		pq.push({a[i]});
		int x = floor(i * 1.0 * w);
		x = max(x, 1ll);
		for(int j = 1; j <= x; j ++){
			pos[j] = pq.top().val;
			pq.pop();
	    }
	    cout << pos[x] << " ";
		for(int j = 1; j <= x; j ++){
			pq.push({pos[j]});
		}
	}
	return 0;
}

赛后题解

可以用一个数组来存,然后循环1到n表示看前i个人的成绩,(sort)从1到n来看先把人数求出来把前i个人排序,然后第人数个就是分数线;(插入)从1到n来看把人数求出来后从i到2如果前面的比现在的小就交换;(桶)枚举1到n每次统计a[i],把人数求出来后,从600循环到0当第j分的人大于人数那就输出j,不然就人数减去j分的人。

补题代码

// 在此粘贴考场代码 //sort(55分)

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1000005;
int n, w, a[MAXN];

int cmp(int x, int y){
	return x > y;
}

signed main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin >> n >> w;
    for(int i = 1; i <= n; i ++){
    	cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		int renshu = max(1ll, i * w / 100);
		sort(a + 1, a + i + 1, cmp);
		cout << a[renshu] << " ";
	}
	return 0;
}

//插入排序(85分)

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1000005;
int n, w, a[MAXN];

signed main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin >> n >> w;
    for(int i = 1; i <= n; i ++){
    	cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		int renshu = max(1ll, i * w / 100);
		for(int j = i; j >= 2; j --){
			if(a[j] > a[j - 1]){
				swap(a[j], a[j - 1]);
			}
		}
		cout << a[renshu] << " ";
	}
	return 0;
}

//桶排序(100分)

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1000005;
int n, w, sum[MAXN], a[MAXN];

signed main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cin >> n >> w;
    for(int i = 1; i <= n; i ++){
    	cin >> a[i];
	}
	for(int i = 1; i <= n; i ++){
		sum[a[i]] ++;
		int renshu = max(1ll, i * w / 100);
		for(int j = 600; j >= 0; j --){
			if(sum[j] < renshu){
				renshu -= sum[j];
			}
			else{
				cout << j << " ";
				break;
			}
		}
	}
	return 0;
}

复杂度

时间复杂度:1.n*nlog(n)2.on方 3.n *600 空间复杂度: 本题总结

T3:方格取数

本题得分:0分 开始时间:2:24 结束时间:3:00 总用时:36分

初始思路

用dfs()或bfs()。

考场解题过程

用bfs()。

考场代码

// 在此粘贴考场代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1e6 + 5;

int dx[105] = {0, 1, -1, 0};
int dy[105] = {0, 0, 0, 1};

int n, m, a[1005][1005], vis[1005][1005], maxi = -1e9;
struct Node{
	int xpos, ypos, step;
};

void bfs(int qx, int qy){
	memset(vis, 0, sizeof(vis));
	queue<Node> q;
	q.push({qx, qy, a[qx][qy]});
	vis[qx][qy] = 1;
	while(q.size() > 0){
		Node tmp = q.front();
		q.pop();
		if(tmp.xpos == n && tmp.ypos == m){
			maxi = max(maxi, tmp.step);
		}
		for(int i = 1; i <= 3; i ++){
			int nx = dx[i] + tmp.xpos;
			int ny = dy[i] + tmp.ypos;
			if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && vis[nx][ny] == 0){
				vis[nx][ny] = 1;
				q.push({nx, ny, tmp.step + a[nx][ny]});
			}
		}
	}
	return ;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freopen("number.in", "r", stdin);
	freopen("number.out", "w", stdout);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= m; j ++){
			cin >> a[i][j];
		}
	}
	bfs(1, 1);
	cout << maxi;
	return 0;
}

赛后题解

用dfs(),因为bfs()只能求最小步数问题。从一,一开始把所有的走法都走一遍,用ans记录走到(i,j)的和,当走到(n,m)的位置时,max一下。

补题代码

// 在此粘贴考场代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1000005;
int n, m, a[1005][1005], vis[1005][1005], maxi = -1e9, ans;
int dx[105] = {0, 1, -1, 0};
int dy[105] = {0, 0, 0, 1};
void dfs(int x, int y){
	if(x == n && y == m){
		maxi = max(maxi, ans);
	}
	for(int i = 1; i <= 3; i ++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && vis[nx][ny] == 0){
			vis[nx][ny] = 1;
			ans += a[nx][ny];
			dfs(nx, ny);
			vis[nx][ny] = 0;
			ans -= a[nx][ny];
		}
	}
}

signed 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 = 1; j <= m; j ++){
    		cin >> a[i][j];
		}
	}
	vis[1][1] = 1;
	ans = a[1][1];
	dfs(1, 1);
	cout << maxi;
	return 0;
}

复杂度

时间复杂度:4的n*m次方 空间复杂度:

本题总结

T4:无

本题得分: 开始时间: 结束时间: 总用时:

初始思路

考场解题过程

考场代码

// 在此粘贴考场代码

赛后题解

补题代码

// 在此粘贴考场代码

复杂度

时间复杂度:

本题总结

四、整体反思

做得较好的地方:思路正确。

需要改进的地方:要多几种情况,要多尝试。

时间安排总结:不要一直想一道题

原文