哔哩哔哩 9月13号 笔试

第一题:弹幕防挡题
import java.io.*;
import java.util.ArrayList;

public class Main {
    public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    public static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
    public static ArrayList<StringBuilder> list = new ArrayList<>();
    public static void main(String[] args) throws IOException {
        String data = null;
        while ((data = reader.readLine())!=null){
            StringBuilder builder = new StringBuilder();

            for (int i=0;i<data.length();i++){
                char ch = data.charAt(i);
                if(ch == '0' || ch == '1') builder.append(data.charAt(i));
            }

            list.add(builder);
        }

        int maxx = 0;
        for (int i=0;i<list.size();i++){
            StringBuilder d = list.get(i);
            for (int j=0;j<d.length();j++)
                maxx = Math.max(maxx,digui(i,j));
        }

        writer.write(""+maxx);
        writer.newLine();
        writer.flush();
    }

    private static int digui(int x, int y) {
        if(x<0 || x>=list.size() || y < 0 || y >=list.get(x).length() || list.get(x).charAt(y)=='0') return 0;
        list.get(x).setCharAt(y,'0');
        return digui(x+1,y)+digui(x-1,y)+digui(x,y+1)+digui(x,y-1)+1;
    }
}
第二题:顺时针打印多维矩阵
    这题忘记存储代码了,哈哈哈
第三题:一发子弹,在一个矩阵中,任意方向开狙,最多打多少个怪
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

public class Main {
    public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    public static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
    public static int n,m;
    public static void main(String[] args) throws IOException {
        String data = null;
        data = reader.readLine();
        HashMap<Integer,Integer> zuo = new HashMap<>();
        HashMap<Integer,Integer> you = new HashMap<>();
        HashMap<Integer,Integer> hen = new HashMap<>();
        HashMap<Integer,Integer> shu = new HashMap<>();
        n = Integer.parseInt(data.trim().split("[ ]+")[0]);

        int maxx = 0;

        for (int i=0;i<n;i++){
            String sub[] = reader.readLine().trim().split("[ ]+");
            int x  = Integer.parseInt(sub[0]);
            int y = Integer.parseInt(sub[1]);

            hen.put(x,hen.getOrDefault(x,0)+1);
            shu.put(y,shu.getOrDefault(y,0)+1);
            zuo.put(x-y,zuo.getOrDefault(x-y,0)+1);
            you.put(x+y,you.getOrDefault(x+y,0)+1);



            maxx = Math.max(hen.get(x),maxx);
            maxx = Math.max(shu.get(y),maxx);
            maxx = Math.max(zuo.get(x-y),maxx);
            maxx = Math.max(you.get(x+y),maxx);
        }


        writer.write(""+maxx);
        writer.newLine();
        writer.flush();



    }

}


#哔哩哔哩笔试##笔经##哔哩哔哩#
全部评论
第三题子弹只允许四个方向吗?
点赞 回复 分享
发布于 2021-09-13 20:58

相关推荐

01-02 21:17
已编辑
西安理工大学 后端
程序员小白条:项目不太重要,你的优势的算法竞赛,然后多背相关的八股文,项目可以不作为重点考虑,面试可能就简单带过项目就行了,你可以直接写简历,背项目相关的八股文就行,也不用自己做,时间紧张的情况下,性价比最高
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客企业服务