跳到正文

个人记录

2024年12月18日下午测试 总结

_Missile_约 6 分钟
原文
文章信息与版本

文章信息

收录
2026年5月10日
更新
2026年7月25日
篇幅
约 6 分钟

版本

  1. v2当前
  2. v1

考试情况

题目分数改题用时改后分数
A1000s100
B202s100
C40无40
D205min100
E0无0
F60无60
G0无0

A

第一次就是满分

思路

用数组模拟每一次的操作

B

错误原因

十年OI一场空,不开longlong见祖宗十年OI一场空,不开long long见祖宗

思路

先从小到大排序,再求个前缀和以便后面求和时不用再次扫一遍,然后每次输入x, y就直接用前缀和数组求从n - (x - y)到n - x + 1的和即可

错误代码

C++
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 114;

int n, q, a[N], b[N], x, y;

int main(){
///	freopen("B.in", "r", stdin);
///	freopen("B.out", "w", stdout);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++){
		b[i] = b[i - 1] + a[i];
	}
	while(q--){
		cin >> x >> y;
		cout << b[n - (x - y)] - b[n - x] << '\n';
	}
	return 0;
}

正确代码

C++
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 2e5 + 114;

ll n, q, a[N], b[N], x, y;

int main(){
///	freopen("B.in", "r", stdin);
///	freopen("B.out", "w", stdout);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> q;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++){
		b[i] = b[i - 1] + a[i];
	}
	while(q--){
		cin >> x >> y;
		cout << b[n - (x - y)] - b[n - x] << '\n';
	}
	return 0;
}

错误的地方

C++
int n, q, a[N], b[N], x, y;
///变为 ll n, q, a[N], b[N], x, y;

C

错误原因

骗分

错误代码

C++
#include <bits/stdc++.h>

using namespace std;

int main(){
///	freopen("C.in", "r", stdin);
///	freopen("C.out", "w", stdout);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout << 0;
	return 0;
}

正确代码

还没改出来

D

错误原因

DP写了多余的初始化

思路

一维DP,DP[i]表示花i元能得到的最大价值

错误代码

C++
#include <bits/stdc++.h>

using namespace std;

const int N = 114, M = 1e5 + 114;

int t, n, P, Q, p[N], q[N], dp[M];

int main(){
///	freopen("D.in", "r", stdin);
///	freopen("D.out", "w", stdout);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> t;
	while(t--){
		cin >> n >> P >> Q;
		fill(dp + 0, dp + Q * 2 + 5, 0);
		for(int i = 1; i <= n; i++){
			cin >> p[i] >> q[i];
			dp[q[i]] = p[i];
		}
		for(int i = 1; i <= n; i++){
			for(int j = q[i]; j <= Q; j++){
				dp[j] = max(dp[j], dp[j - q[i]] + p[i]);
			}
		}
		int ans = -1;
		for(int i = 1; i <= Q; i++){
			if(dp[i] >= P){
				ans = i;
				break;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

正确代码

C++
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 114, M = 1e5 + 114;

ll t, n, P, Q, p[N], q[N], dp[M];

int main(){
///	freopen("D.in", "r", stdin);
///	freopen("D.out", "w", stdout);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> t;
	while(t--){
		cin >> n >> P >> Q;
		fill(dp + 0, dp + Q * 2 + 5, 0);
		for(int i = 1; i <= n; i++){
			cin >> p[i] >> q[i];
		}
		for(int i = 1; i <= n; i++){
			for(int j = Q; j >= q[i]; j--){
				dp[j] = max(dp[j], dp[j - q[i]] + p[i]);
			}
		}
		ll ans = -1;
		for(int i = 0; i <= Q; i++){
			if(dp[i] >= P){
				ans = i;
				break;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

错误的地方

C++
dp[q[i]] = p[i];///不需要
原文