成都市网站建设_网站建设公司_前端开发_seo优化
2026/1/18 10:45:17 网站建设 项目流程

​欢迎大家订阅我的专栏:算法题解:C++与Python实现!
本专栏旨在帮助大家从基础到进阶 ,逐步提升编程能力,助力信息学竞赛备战!

专栏特色
1.经典算法练习:根据信息学竞赛大纲,精心挑选经典算法题目,提供清晰的代码实现与详细指导,帮助您夯实算法基础。
2.系统化学习路径:按照算法类别和难度分级,从基础到进阶,循序渐进,帮助您全面提升编程能力与算法思维。

适合人群:

  • 准备参加蓝桥杯、GESP、CSP-J、CSP-S等信息学竞赛的学生
  • 希望系统学习C++/Python编程的初学者
  • 想要提升算法与编程能力的编程爱好者

附上汇总帖:AtCoder Beginner Contest竞赛题解 | 汇总


A - Feet

【题目来源】

洛谷:[AT_abc437_a ABC437A] Feet - 洛谷

【题目描述】

\(1\) foot is \(12\) inches.
\(1\) 英尺等于 \(12\) 英寸。

How many inches is \(A\) feet \(B\) inches?
\(A\) 英尺 \(B\) 英寸是多少英寸?

【输入】

The input is given from Standard Input in the following format:

\(A\) \(B\)

【输出】

Output the answer in one line. Omit the unit (inches).

【输入样例】

6 7

【输出样例】

79

【代码详解】

#include <bits/stdc++.h>
using namespace std;int a, b;  // 定义两个整数变量a和bint main()
{// 输入两个整数a和bcin >> a >> b;// 计算并输出结果:a * 12 + bcout << a * 12 + b << endl;return 0;  // 程序正常结束
}

【运行结果】

6 7
79

B - Tombola

【题目来源】

洛谷:[AT_abc437_b ABC437B] Tombola - 洛谷

【题目描述】

There is a grid with \(H\) rows and \(W\) columns. Each square has one integer written on it, and these integers are distinct. The square at the \(i\) -th row from the top and \(j\) -th column from the left has the integer \(A_{i,j}\) written on it.
有一个 \(H\)\(W\) 列的网格。每个方格上写有一个整数,且这些整数互不相同。位于从上往下第 \(i\) 行、从左往右第 \(j\) 列的方格上写有整数 \(A_{i,j}\)

Now, the host called out \(N\) distinct integers \(B_1, \dots, B_N\) .
现在,主持人报出了 \(N\) 个互不相同的整数 \(B_1, …, B_N\)

If you find, for each row, how many of the integers called out by the host are contained in that row, what is the maximum value among these?
若针对每一行,统计该行中包含的主持人所报出的整数个数,则这些个数中的最大值是多少?

【输入】

The input is given from Standard Input in the following format:

\(H\) \(W\) \(N\) \(A_{1,1}\) \(\cdots\) \(A_{1,W}\) \(\vdots\) \(A_{H,1}\) \(\cdots\) \(A_{H,W}\) \(B_1\) \(\vdots\) \(B_N\)

【输出】

Output the answer in one line.

【输入样例】

3 4 5
12 3 5 7
6 10 11 9
1 2 4 8
2
4
9
6
11

【输出样例】

3

【代码详解】

#include <bits/stdc++.h>
using namespace std;const int N = 95;  // 最大矩阵大小
int h, w, n;       // h: 行数, w: 列数, n: 数字列表长度
int a[N][N];       // h×w的矩阵
int b[N];          // 包含n个数字的列表int main()
{// 输入矩阵的行数、列数和数字列表长度cin >> h >> w >> n;// 输入矩阵元素for (int i = 1; i <= h; i++){for (int j = 1; j <= w; j++){cin >> a[i][j];}}// 输入数字列表for (int i = 1; i <= n; i++){cin >> b[i];}int maxn = -1e9;  // 初始化最大计数为极小值// 遍历每一行for (int i = 1; i <= h; i++){int cnt = 0;  // 当前行的匹配计数// 遍历当前行的每个元素for (int j = 1; j <= w; j++){// 遍历数字列表中的每个数字for (int k = 1; k <= n; k++){// 如果矩阵元素等于列表中的数字if (b[k] == a[i][j]){cnt++;  // 增加计数}}}// 更新最大计数maxn = max(maxn, cnt);}// 输出最大计数cout << maxn << endl;return 0;
}

【运行结果】

3 4 5
12 3 5 7
6 10 11 9
1 2 4 8
2
4
9
6
11
3

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询