# 字节跳动2019届校招笔试题

1.世界杯开幕式会在球场C举行，球场C的球迷看台可以容纳M*N个球迷。在球场售票完成后，现官方想统计此次开幕式一共有多少个球队球迷群体，最大的球队球迷群体有多少人。

10，10

0,0,0,0,0,0,0,0,0,0

0,0,0,1,1,0,1,0,0,0

0,1,0,0,0,0,0,1,0,1

1,0,0,0,0,0,0,0,1,1

0,0,0,1,1,1,0,0,0,1

0,0,0,0,0,0,1,0,1,1

0,1,1,0,0,0,0,0,0,0

0,0,0,1,0,1,0,0,0,0

0,0,1,0,0,1,0,0,0,0

0,1,0,0,0,0,0,0,0,0

## java实现：

public class Problem1 {
static String input = "10,10\n" +
"0,0,0,0,0,0,0,0,0,0\n" +
"0,0,0,1,1,0,1,0,0,0\n" +
"0,1,0,0,0,0,0,1,0,1\n" +
"1,0,0,0,0,0,0,0,1,1\n" +
"0,0,0,1,1,1,0,0,0,1\n" +
"0,0,0,0,0,0,1,0,1,1\n" +
"0,1,1,0,0,0,0,0,0,0\n" +
"0,0,0,1,0,1,0,0,0,0\n" +
"0,0,1,0,0,1,0,0,0,0\n" +
"0,1,0,0,0,0,0,0,0,0";

static class Person {
int num;
int reach;

public Person(int num, int reach) {
this.num = num;
this.reach = reach;
}

@Override
public String toString() {
return "Person{" +
"num=" + num +
", reach=" + reach +
'}';
}
}

static Person[][] handleInput() {
String[] lines = input.split("\n");
String[] first = lines[0].split(",");
int row = Integer.valueOf(first[0]);
int col = Integer.valueOf(first[1]);
Person[][] arr = new Person[row][col];
String[] line;
for (int i = 1; i < lines.length; i++) {
line = lines[i].split(",");
for (int j = 0; j < line.length; j++) {
arr[i - 1][j] = new Person(Integer.valueOf(line[j]), 0);
}
}
return arr;
}

static void searchMaxPerson(Person[][] arr) {
int row = arr.length;
int col = arr[0].length;
int tmp ;
int max = 0;
int count = 0;
Person cur;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
cur = arr[i][j];
if (cur.num != 0 && cur.reach == 0) {
count ++;
tmp = searchAll(arr,i,j);
if(tmp > max){
max = tmp;
}
}
}
}
System.out.println(count+","+max);
}

static int searchAll(Person[][] arr, int r, int c) {
int row = arr.length;
int col = arr[0].length;
if (r >= row || r < 0 || c >= col || c < 0) {
return 0;
}
Person cur = arr[r][c];
if (cur.num != 0 && cur.reach == 0) {
cur.reach = 1;
int n1 = searchAll(arr, r - 1, c) + searchAll(arr, r + 1, c);
int n2 = searchAll(arr, r - 1, c - 1) + searchAll(arr, r + 1, c + 1);
int n3 = searchAll(arr, r, c - 1) + searchAll(arr, r, c + 1);
int n4 = searchAll(arr, r - 1, c + 1) + searchAll(arr, r + 1, c - 1);
return n1 + n2 + n3 + n4 + 1;
}
return 0;
}

public static void main(String[] args) {
Person[][] arr = handleInput();
searchMaxPerson(arr);
}
}