AtCoder Beginner Contest 151 题解报告

总的来说,这次的目比较水,然而菜菜的我并没有把所有目都做完,话不多说,直接来干货:

A:Next Alphabet

题目链接:https://atcoder.jp/contests/abc151/tasks/abc151_a

题目描述:Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order. 大致解读:给你一个小写字母,输出这个小写字母的后一个字母(所有样例中不会有 z 字母的出现) 样例: input :a output:b

AC代码:

#include<iostream> #include<cstring> #include<string> using namespace std; int main(void) { string str; cin >> str; printf("%c\n",str[0] + 1); return 0; } B: Achieve the Goal

题目链接:https://atcoder.jp/contests/abc151/tasks/abc151_b

题目描述:Takahashi is taking exams on N subjects. The score on each subject will be an integer between 0 and K(inclusive).He has already taken exams on N−1 subjects and scored A i points on the i-th subject.His goal is to achieve the average score of M points or above on the N subjects. Print the minimum number of points Takahashi needs on the final subject to achieve his goal. If the goal is unachievable, print -1 instead. 大致解读:题目中会给你 N - 1 个数,然后需要找满足某种条件的第 N 个数,问是否存在这样的一个数,如果存在,输出这个数。 不存在,则输出 '-1'。 寻找的这个数的条件: 1、范围必须在0 ~ k(包括0 and k) 2、与前 N - 1个数的平均值在 M 及 M 之上 (英文的重要性,hh) 样例: input :5 10 7 8 10 3 6 output :8 析题有解:初看这道题,感觉是数论,(哈哈,实际上是自己见的东西太少了,根本不是数论),然后直接就去做后面的题了,A了第三题 之后,看榜单发现大家都做了这道题,这么多人能做出来,我也一定可以,然后再去读题,发现竟然如此水,主要还是自己 英文不好,题没读懂,哈哈哈。

AC代码:

#include<iostream> #include<algorithm> using namespace std; const int maxn = 105; int n,k,m,sum; float aver; int main(void) { cin >> n >> k >> m; sum = 0; for(int i = 1; i <= n - 1; i ++) { int num; cin >> num; sum += num; } for(int j = 0; j <= k; j ++) { aver = (sum + j) * 1.0 / n; if(aver >= m) { cout << j << endl; return 0; } } cout << "-1" << endl; return 0; } C:Welcome to AtCoder

题目链接:https://atcoder.jp/contests/abc151/tasks/abc151_c

题目描述:Takahashi participated in a contest on AtCoder.The contest had N problems. Takahashi made M submissions during the contest.The i-th submission was made for the pi-th problem and received the verdict Si (AC or WA). The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem. Find the numbers of Takahashi's correct answers and penalties. 大致解读: 与我们平常在网站上做题目交题时评测机类似,根据 AC 和 WA 来判断 A 了几道题,在 A 完给出的所以 题之前我们 WA 掉了几次,最后输出 AC 题目结果和 我们所有 WA 了的次数。 注意:一道题目 AC 过后之后 WA 的结果就不再被累计(常识的东西就不再一一介绍了,可以自己找OJ测试一下) 样例 : input : 2 5 1 WA 1 AC 2 WA 2 AC 2 WA outout: 2 2

AC代码:

#include<iostream> #include<algorithm> #include<cstring> #include<string> #include<map> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; map<int,int>maps; map<int,int>::iterator it; int n,m; int ac = 0,wa = 0; int main(void) { void solve(); cin >> n >> m; ac = wa = 0; solve(); return 0; } void solve() { if(m == 0) { cout << 0 << " " << 0 << endl; return ; } int num; string vis; for(int i = 1; i <= m; i ++) { cin >> num >> vis; if(maps[num] == -1) continue; if(vis == "AC") { wa += maps[num]; ac += 1; maps[num] = -1; continue; } maps[num] ++; } maps.clear(); cout << ac << " " << wa << endl; return ; } D:Maze Master

题目链接:https://atcoder.jp/contests/abc151/tasks/abc151_d

题目描述:Takahashi has a maze, which is a grid of H × W squares with H horizontal rows and W vertical columns.The square at the i-th row from the top and the j-th column is a "wall" square if Sij is #, and a "road" square if Sij is .. From a road square, you can move to a horizontally or vertically adjacent road square. You cannot move out of the maze, move to a wall square, or move diagonally.Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki. Aoki will then travel from the starting square to the goal square, in the minimum number of moves required. In this situation, find the maximum possible number of moves Aoki has to make. 大致解读:有一个 H * W 的迷宫,自己任意定义一个起点和终点,找到一个最远的距离且是存在一条最短路径,输出这条路的最短步数。 数值范围:1≤H,W≤20 样例: input :3 3 ... ... ... output: 4 input:3 5 ...#. .#.#. .#... output: 10 析题有解:这道题有一个需要特别注意的地方,就是数值范围,最大是 20 ,这么小的范围,当然暴力来一发咯,哈哈。 起点和终点都没有给我们,而我们又要求一个最大值,只能逐个遍历每一个合适的点,寻找满足这个点的合 适路径的最少步数。 考察算法:BFS经典走迷宫

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzxdjs.html