3.26雷火笔试

今天笔试题感觉还都挺水的。。。
第一题就算一下二维数组的和
#include <bits/stdc++.h>

using namespace std;
const int N = 110;
int a[N][N];
int n,m,x,y;

int main() {
    int n,m,x,y;
    scanf("%d%d%d%d",&n,&m,&x,&y);
    int ans = 0;
    for(int i = 1;i <= n;i++) {
       for(int j = 1;j <= m;j++){
        scanf("%d",&a[i][j]);
        ans += a[i][j];
       }
    }
    printf("%d\n",ans - a[x][y] + 1);
    return 0;
}
第二题模拟一下就行了
#include <bits/stdc++.h>

using namespace std;
const int N = 100;
vector<int> num[N],kind[N];
int a[N];
char str[N];
bool st[N];
int n;

bool check1() {
    for(int i = 0;i < N;i++) if(num[i].size() == 2) return true;
    return false;
}

bool check2() {
    int res = 0;
    for(int i = 0;i < N;i++) {
        if(num[i].size() >= 2) res++;
    }
    return res >= 2;    
}

bool check3() {
    for(int i = 0;i < N;i++) if(num[i].size() >= 3) return true;
    return false;
}

bool check4() {
    for(int i = 0;i + 4 < N;i++) {
        if(num[i].size() && num[i + 1].size() && num[i + 2].size() && num[i + 3].size() && num[i + 4].size()) return true;
    }
    return false;
}
bool check5() {
    int res1 = 0,res2 = 0;
    for(int i = 0;i < N;i++) {
        if(num[i].size() == 2) res1 = 1;
        if(num[i].size() == 3) res2 = 1;
    }
    return (res1 + res2 == 2);
}
bool check6() {
    for(int i = 0;i < N;i++) if(num[i].size() == 4) return true;
    return false;
}
bool check7() {
    for(int i = 0;i < N;i++) if(kind[i].size() == 5) return true;
    return false;
}
bool check8() {
    for(int i = 0;i < N;i++) {
        if(kind[i].size() == 5) {
            for(int j = 0;j < N;j++) st[j] = 0;
            for(int x:kind[i]) st[x] = 1;
            for(int j = 0;j + 4 < N;j++) 
                if(st[j] && st[j + 1] && st[j + 2] && st[j + 3] && st[j + 4]) return true;
        }
    }
    return false;
}
bool check9() {
    for(int i = 0;i < N;i++) if(num[i].size() == 5) return true;
    return false;
}


int main() {
    int T;
    cin >> T;
    while(T--) {
        for(int i = 0;i < N;i++) num[i].clear(),kind[i].clear();
        cin >> n;
        for(int i = 1;i <= n;i++) cin >> a[i];
        for(int i = 1;i <= n;i++) cin >> str[i];
        for(int i = 1;i <= n;i++) {
            int x = a[i];
            char ch = str[i];
            kind[ch - 'A'].push_back(x);
            num[x].push_back(ch - 'A');
        }
        int  res = 1;
        if(check1()) res = 2;
        if(check2()) res = 4;
        if(check3()) res = 6;
        if(check4()) res = 20;
        if(check5()) res = 40;
        if(check6()) res = 150;
        if(check7()) res = 300;
        if(check8()) res = 8000;
        if(check9()) res = 15000;
        printf("%d\n",res);
    }
    return 0;
}
第三题模拟一下即可
#include <bits/stdc++.h>

using namespace std;
const int N = 3e3 + 10;
string str;
int n,m;

int check_kind(char c) {
    if((c >= 'a' && c <= 'z' || (c >= 'A') && c <= 'Z')) return 0;
    if(c == ' ') return 1;
    return 2;
}

int length(string t,int pos) {
    int num = t.length();
        int st = pos;
        while(pos < num && check_kind(t[pos]) == 0) pos++;
        return pos - st;
}

int fun() {
    vector<string> v;
    v.clear();
    int num = str.length();
    for(int i = 0;i < num;i++) {
        string t = "";
        if(check_kind(str[i]) == 1) i++;
        int p = min(num,i + n);
        while(i < p) {
            t.push_back(str[i]);
            i++;
        }
        if(i < num && check_kind(str[i]) == 0 &&check_kind(t.back()) == 0) {
            int len = length(str,i);
            if(len <= m) {
                for(int k = 0;k < len;k++) t.push_back(str[i++]);
            }
            else {
                while(check_kind(t.back()) == 0) {
                    i--;
                    t.pop_back();
                }
            }
        }
        if(i < num && check_kind(str[i]) == 2) {
            t.push_back(str[i++]);
        }
        i--;
        v.push_back(t);
    }
    for(string s:v) while(s.back() == ' ') s.pop_back();
    cout << v.size() << endl;
    for(string t:v) cout << t << endl;
    return v.size();
}

int main() {
   scanf("%d%d ",&n,&m);
   getline(cin,str);
   fun();
}

第四题二分 + bfs
#include <bits/stdc++.h>

using namespace std;
const int N = 800;
int sx,sy,ex,ey;
int a[N][N];
bool st[N][N];
int n,m;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

struct Node{
    int x,y;
};

bool check(int mid) {
    queue<Node> q;
    memset(st,0,sizeof st);
    st[sx][sy] = 1;
    q.push({sx,sy});
    while(q.size()) {
        Node t = q.front();
        q.pop();
        for(int i = 0;i < 4;i++) {
            int x = t.x + dx[i];
            int y = t.y + dy[i];
            if(x < 1 || y < 1 || x > n || y > m) continue;
            if(st[x][y] || a[x][y] > mid) continue;
            st[x][y] = 1;
            q.push({x,y});
        }
    }   
    return st[ex][ey];
}

int main() {
    scanf("%d%d%d%d%d%d",&n,&m,&sx,&sy,&ex,&ey);
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++)
            scanf("%d",&a[i][j]);
    int l = a[sx][sy],r = 490000;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(check(mid)) r = mid;
        else l = mid + 1;
    }
    printf("%d\n", l);
    return 0;
}


#笔试##网易雷火##笔试题目#
全部评论
第三题,不是每行不超过n+m吗?样例第二行的the不应该在第一行吗?
1 回复 分享
发布于 2022-03-26 17:21
是不是只有编程题哇?
点赞 回复 分享
发布于 2022-08-12 16:44
挺水的。。。 大佬好厉害
点赞 回复 分享
发布于 2022-03-27 11:29
楼主您好,考虑蚂蚁实习吗。 岗位介绍: https://m.nowcoder.com/discuss/868274 如果有意向的话,可以加我微信了解呢。longterm-value(备注: 牛客 网)
点赞 回复 分享
发布于 2022-03-26 18:32
第三题我写出来了,本地没问题,在牛客上就是过不了,气死我了
点赞 回复 分享
发布于 2022-03-26 17:51
刚做这场,第二题过了0%,当场就不想做了。看到你的代码才发现,他的效果是不可叠加的吗?
点赞 回复 分享
发布于 2022-03-26 17:17

相关推荐

自由水:这HR已经很好了,多的是已读不回和不读了
点赞 评论 收藏
分享
评论
点赞
11
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务