米哈游笔试

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,

// then press Enter. You can now see whitespace characters in your code.

class Node {

// 父亲编号

public int parval;

public boolean isleaf;

// 当前编号

public int val;

public Node(int parval, boolean isleaf, int val) {

this.isleaf = isleaf;

this.parval = parval;

this.val = val;

}

public Node() {

}

}

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int[] array = new int[2];

for (int i = 0; i < array.length; i++) {

array[i] = scanner.nextInt();

}

int count = array[0];

int k = array[1];

ArrayList<Node> nodes = new ArrayList<>();

for (int i = 0; i < count + 1; i++) {

nodes.add(new Node());

}

for (int i = 0; i < count - 1; i++) {

int[] nums = new int[2];

for (int j = 0; j < nums.length; j++) {

nums[j] = scanner.nextInt();

}

nodes.get(nums[0]).isleaf = false;

nodes.get(nums[0]).val = nums[0];

nodes.get(nums[1]).isleaf = true;

nodes.get(nums[1]).parval = nums[0];

nodes.get(nums[1]).val = nums[1];

}

int max = 0;

for (int i = 1; i <= count; i++) {

int step = calStep(nodes, nodes.get(i));

if (step <= k) {

max++;

}

if (nodes.get(i).isleaf && step < k) {

nodes.add(new Node(i, true, ++count));

}

}

System.out.println(max);

}

public static int calStep(ArrayList<Node> nodes, Node node) {

int cur = node.val;

int step = 0;

while (nodes.get(cur).parval != 0) {

cur = nodes.get(cur).parval;

step++;

}

return step;

}

}

我**没问题啊,给我0是为啥

全部评论

相关推荐

吐泡泡的咸鱼:我也工作了几年了,也陆陆续续面试过不少人,就简历来说,第一眼学历不太够,你只能靠你的实习或者论文或者项目经历,然后你没有论文,没有含金量高的比赛和奖项,只能看实习和项目,实习来说,你写的实习经历完全不清楚你想找什么工作?行研?数据分析?且写的太少了,再看项目,这些项目先不说上过大学读过研究生的都知道很水,然后对你想找的岗位有什么帮助呢?项目和实习也完全不匹配啊,你好像在努力将你所有的经历都放在简历里想表现你的优秀,但是对于你想找的岗位来说,有什么用呢?最后只能获得岗位不匹配的评价。所以你需要明白你想要找的岗位要求是什么,是做什么的,比如产品经理,然后再看你的经历里有什么匹配的上这个岗位,或者对这个岗位以及这个岗位所在的公司有价值,再写到你的简历上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务