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经典走迷宫
AC代码:
方法一(结构体的运用 + 标记):
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<string.h>
#include<limits.h>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
const int maxn = 25;
char str[maxn][maxn];
int vis[maxn][maxn];
struct node { // 结构体将其信息绑定到一起
int x,y,step;
} dot[maxn];
int dir[][2] = {{1,0},{-1,0},{0,1},{0,-1}}; // 方向
int n,m;
int ans = 0,res = 0;
int main(void) {
int BFS(int start_x,int start_y);
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i ++) {
for(int j = 0; j <= m; j ++) { // 有换行字符,所以从 0 开始
scanf("%c",&str[i][j]);
}
}
ans = 0;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
if(str[i][j] == '#') continue;
res = BFS(i,j);
ans = max(ans,res);
}
}
cout << ans << endl;
return 0;
}
bool Check(int x,int y) {
if(x < 1 || y < 1 || x > n || y > m) return false;
if(vis[x][y] || str[x][y] == '#') return false;
if(str[x][y] == '.') return true;
}
int BFS(int start_x,int start_y) {
memset(vis,0,sizeof(vis)); // 复原
int count = 0;
queue<node>queues;
while(!queues.empty()) queues.pop();
node first,second;
first.x = start_x,first.y = start_y,first.step = 0;
queues.push(first);
vis[start_x][start_y] = 1;
while(!queues.empty()) {
first = queues.front();
queues.pop();
count = max(count,first.step); // 每次进行比较得到最大的值
for(int i = 0; i < 4; i ++) {
second.x = first.x + dir[i][0];
second.y = first.y + dir[i][1];
if(!Check(second.x,second.y)) continue; // 注意这里用 ! (这里卡了好久,一定要记得自己写的Check函数返回的是什么)
second.step = first.step + 1;
queues.push(second);
vis[second.x][second.y] = 1;
}
}
return count;
}
方法二(pair的运用,参考大佬写的,感觉相对于结构体来说,更好用一点,再次特地感谢那位无名大佬):
大致思路类似:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<limits.h>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define P pair<int,int>
#define x first
#define y second
using namespace std;
const int maxn = 25;
char str[maxn][maxn];
int num[maxn][maxn];
int dir[][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int n,m,ans,res;
queue<P>Q;
int main(void) {
int BFS(int start_x,int start_y);
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i ++) {
for(int j = 0; j <= m; j ++) {
scanf("%c",&str[i][j]);
}
}
ans = 0,res = 0;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++ ) {
if(str[i][j] == '#') continue;
res = BFS(i,j);
ans = max(ans,res);
}
}
cout << ans << endl;
return 0;
}
bool Check(int x,int y) {
if(x < 1 || y < 1 || x > n || y > m) return false;
if(str[x][y] == '#' || num[x][y]) return false;
if(str[x][y] == '.') return true;
}
int BFS(int start_x,int start_y) {
P a,b;
int count = 0;
memset(num,0,sizeof(num));
while(!Q.empty()) Q.pop();
a.x = start_x,a.y = start_y;
Q.push(a);
while(!Q.empty()) {
a = Q.front();
Q.pop();
count = max(count,num[a.x][a.y]);
int v = num[a.x][a.y];
for(int i = 0; i < 4; i ++) {
b.x = a.x + dir[i][0];
b.y = a.y + dir[i][1];
if(!Check(b.x,b.y)) continue;
if(b.x != start_x || b.y != start_y) { // 要保证不会回到最初的点,因为这种方法我们没有进行标记
num[b.x][b.y] = v + 1;
Q.push(b);
}
/*
如果不加特殊判断的话就会出现错误,下面是特殊样例:
2 2
#.
#.
*/
}
}
return count;
}
知识总结:
1、复习了 map 容器的运用,更加熟练。
2、对迷宫问题有了更深一步的了解,同时对 BFS 也算回顾复习了一下(Check语句一定要认真,弄清楚返回的是什么)
3、pair<int,int> 的应用,相对于结构体来说,这个的应用更方便一点。
#赛后小结:#
1、认真读题,认真读题,一定要真正读题,有可能一个小小的细节就会导致大错误。
2、大胆一点,有想法就要尝试一下。
3、坚持到比赛最后一秒,不要因为时间快到了就不去想了,也不要因为别人都做出来了而不再去尝试。
···
能力有限,如有写的不到位的地方,望路过的朋友留下您的建议,在下会细心改正,万分感谢。
后续更新 ing............
···
AtCoder Beginner Contest 151 题解报告的更多相关文章
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AtCoder Beginner Contest 172 题解
AtCoder Beginner Contest 172 题解 目录 AtCoder Beginner Contest 172 题解 A - Calc B - Minor Change C - Tsu ...
- AtCoder Beginner Contest 169 题解
AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...
- AtCoder Beginner Contest 148 题解
目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...
- AtCoder Beginner Contest 115 题解
题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit ...
随机推荐
- Python--day64--内容回顾
1,内容回顾 1.ORM外键操作 图书表和出版社表 多对一的关系 #书 class Book(models.Model): id = models.AutoField(primary_key=True ...
- laravel post提交数据时显示异常
post提交数据时候显示如下: The page has expired due to inactivity. Please refresh and try again 这是由于在laravel框架中 ...
- 深度学习——RNN
整理自: https://blog.csdn.net/woaidapaopao/article/details/77806273?locationnum=9&fps=1 原理 RNN.LSTM ...
- H3C 端口隔离配置举例
- vue中 js获取图片尺寸 设置不同样式
1.JS: 请求到后端数据后 判断图片尺寸 2.HTML代码 根据设置的类型,给图片添加不同的样式 3.CSS代码 添加不同尺寸的样式
- Linux网络IO模型
同步和异步,阻塞和非阻塞 同步和异步 关注的是结果消息的通信机制 同步:同步的意思就是调用方需要主动等待结果的返回 异步:异步的意思就是不需要主动等待结果的返回,而是通过其他手段比如,状态通知,回调函 ...
- Team Foundation Server 2015使用教程【6】:新增权限为读取器的团队
- (1)51单片机NOP指令
提问:什么是NOP指令?干什么用的?单片机程序里执行一条nop指令需要多长时间? (1)一个NOP就是一个机器周期 (2)空指令,延时一个机器周期 (3)这个与单片机型号.指令类型和使用的晶振频率有关 ...
- Struts2和Spring集成
Spring是一个流行的Web框架,它提供易于集成与很多常见的网络任务.所以,问题是,为什么我们需要Spring,当我们有Struts2?Spring是超过一个MVC框架 - 它提供了许多其它好用的东 ...
- Visual Studio 2019 编译.Net Core Console项目出现【MSB4018 The "CreateAppHost" task failed unexpectedly】 错误
需要测试一个小东东,使用Visual Studio 2019新建了一个.Net Core的Console程序,但是在编译的时候一直报错,死活编译不通过. 错误信息: Severity Code Des ...