哔哩哔哩 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(); } }