拼多多 2019校园招聘 正式批笔试-2018.8.28

版权声明:本人ZZU在校学生,文章均为个人心得,有不足之处请不吝赐教! https://blog.csdn.net/whl_program/article/details/82230415

1-1
1-2.png
1-3.png
判断一下是否值得蓄力就行

#include <iostream>

using namespace std;

int main()
{
    int HP, normAtck, buffAtck;
    cin >> HP >> normAtck >> buffAtck;
    int res = 0;
    if(buffAtck >= normAtck*2){//值得蓄力
        while(HP > 0){
            HP -= buffAtck;
            res += 2;
        }
        if(HP + buffAtck <= normAtck)//最后一击 不用蓄力 正常能消灭的情况
            res --;
    }else{//不值得蓄力
        while(HP > 0){
            HP -= normAtck;
            res += 1;
        }
    }
    cout << res << endl;
    return 0;
}

2-1.png
2-2.png
2-3.png

#include <iostream>
#include <cstring>
using namespace std;
int main(){
    int n, m;//N行 M列
    cin >> n >> m;
    char board[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> board[i][j];
        }
    }
    for(int i = 0; i < m; i++){//按列处理
        bool flag = false;
        int xLine = -1;//记录x所在的行
        int cnt = 0;//cnt记录o的数量
        for(int j = n -1; j >= 0; j--){//从下到上 按行处理
            if(!flag && board[j][i] == 'o'){//没碰到x之前 o全部清除
                board[j][i] = '.';
            }else if(board[j][i] == 'x'){
                flag = true;
                xLine = j;
                cnt = 1;
            }else if(board[j][i] == 'o'){
                //cout << j << " " << i << endl;
                board[xLine - cnt][i] = 'o';//掉落位置 置为o
                if(xLine - cnt != j){//如果o掉落  就将o原来位置清为.
                    board[j][i] = '.';
                }
                cnt++;
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cout << board[i][j];
        }
        cout << endl;
    }
    return 0;
}

3-1.png
3-2.png
3-3.png
参考链接,点击

#include <bits/stdc++.h>
using namespace std;
int n, m;
unordered_map<int, int> ma;
pair<int, int> solve(int n, int m){
    ma.clear();
    int now = 0;
    int t, h;
    n = n % m;
    while(true){
        n = n % m;
        t = n % m;
        if(ma.find(n) == ma.end()){
            ma[n] = now;
        }else{
            h = now - ma[n];
            return make_pair(ma[n], h);
        }
        //cout << n << " " << m << " " << t << endl;
        if(t == 0){
            return make_pair(now, 0);
        }
        n = t;
        n *= 10;
        now++;
    }
}
int main() {
    //std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    auto ans = solve(n, m);
    cout << ans.first << " " << ans.second << endl;
    return 0;
}

4-1.png
4-2.png
4-3.png
参考链接,点击

#include <bits/stdc++.h>
using namespace std;
int n, m;//n个字符串 长度为m
string sarr[2005];
set<string> se;
set<char> cse[15];
string gs;
bool flag = false;
string ans;
void dfs(int id) {
    if (id >= m) {
        // find
        if (se.find(gs) != se.end()) {
            return;
        } else {
            ans = gs;
            flag = true;
            return;
        }

    }
    auto it = cse[id].begin();
    while(it != cse[id].end()) {
        gs[id] = *it;
        dfs(id + 1);
        if (flag) return;
        ++it;
    }
}
int main() {
    //std::ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for(int i=0; i<n; ++i){
        cin >> sarr[i];
        se.insert(sarr[i]);
        for(int j=0; j<m; ++j){
            cse[j].insert(sarr[i][j]);
        }
    }
    gs = "";
    for(int i=0; i<m; ++i)
        gs += 'a';
    flag = false;
    dfs(0);
    if(flag){
        cout << ans << endl;
    }else{
        cout << "-" << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/whl_program/article/details/82230415