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

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…………

···

版权声明:本文为prjruckyone原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/prjruckyone/p/12189588.html