网站开发平面设计师岗位要求,网站系统使用手册,网站建设公司财务预算,哪些网站是做快消品的题目 为了达到新冠疫情精准防控的需要#xff0c;为了避免全员核酸检测带来的浪费#xff0c;需要精准圈定可能被感染的人群。现在根据传染病流调以及大数据分析#xff0c;得到了每个人之间在时间、空间上是否存在轨迹的交叉。现在给定一组确诊人员编号 (X1, X2, X3, …, n…题目 为了达到新冠疫情精准防控的需要为了避免全员核酸检测带来的浪费需要精准圈定可能被感染的人群。现在根据传染病流调以及大数据分析得到了每个人之间在时间、空间上是否存在轨迹的交叉。现在给定一组确诊人员编号 (X1, X2, X3, …, n)在所有人当中找出哪些人需要进行核酸检测输出需要进行核酸检测的人数。(注意确诊病例自身不需要再做核酸检测) 需要进行核酸检测的人是病毒传播链条上的所有人员即有可能通过确诊病例所能传播到的所有人。 例如A是确诊病例A和B有接触、B和C有接触、C和D有接触、D和E有接触那么B\C\D\E都是需要进行核酸检测的人。 输入描述 第一行为总人数N 第二行为确诊病例人员编号(确诊病例人员数量N)用逗号分割 第三行开始为一个N*N的矩阵表示每个人员之间是否有接触0表示没有接触1表示有接触。 输出描述 整数需要做核酸检测的人数 补充说明 人员编号从0开始 0  N  100 1 示例 输入 5 1,2 1,1,0,1,0 1,1,0,0,0 0,0,1,0,1 1,0,0,1,0 0,0,1,0,1 1 2 3 4 5 6 7 输出 3 1 补充说明 编号为1、2号的人员为确诊病例。1号和0号有接触0号和3号有接触。 2号和4号有接触。所以需要做核酸检测的人是0号、3号、4号总计3人需要进行核酸检测 参考代码 
方法并查集 
package RealTest;
import java.util.*;/*** ClassName nucleicAcidNumber* Description TODO* Author 21916* Date 2024/3/27 14:58*/class UF{int count;int[] parent;public UF(int n){this.count  n;parent  new int[n];for(int i 0;in;i){parent[i]  i;}}public void union(int p,int q){if(find(p)find(q)) return;parent[p]  q;this.count--;}public int find(int x){if(x!parent[x]){parent[x]   find(parent[x]);}return parent[x];}}
public class nucleicAcidNumber {public static void main(String[] args) {Scanner scanner  new Scanner(System.in);int n  scanner.nextInt();scanner.nextLine(); // Consume newlineString startListStr  scanner.nextLine();String[] arr  startListStr.split(,);SetString set  new HashSet();for(String s:arr){set.add(s);}// System.out.println(startListStr);StringTokenizer tokenizer  new StringTokenizer(startListStr, ,);ListInteger startList  new ArrayList();while (tokenizer.hasMoreTokens()) {startList.add(Integer.parseInt(tokenizer.nextToken()));}int[][] mat  new int[n][n];for (int i  0; i  n; i) {String row  scanner.nextLine();tokenizer  new StringTokenizer(row, ,);for (int j  0; j  n; j) {mat[i][j]  Integer.parseInt(tokenizer.nextToken());}}UF uf  new UF(n);for(int i0;in;i){for(int j0;jn;j){if(mat[i][j]1(set.contains(i)|| set.contains(j))){uf.union(i,j);set.add(i);set.add(j);// System.out.println(此时的countuf.count);}}}System.out.println(n- arr.length-uf.count1);}} 
也可以使用BFS,DFS方法进行搜索 csdn 文章转载自: http://www.morning.pnfwd.cn.gov.cn.pnfwd.cn http://www.morning.msxhb.cn.gov.cn.msxhb.cn http://www.morning.mdplm.cn.gov.cn.mdplm.cn http://www.morning.hwzzq.cn.gov.cn.hwzzq.cn http://www.morning.nmkfy.cn.gov.cn.nmkfy.cn http://www.morning.tnwgc.cn.gov.cn.tnwgc.cn http://www.morning.gtjkh.cn.gov.cn.gtjkh.cn http://www.morning.xnfg.cn.gov.cn.xnfg.cn http://www.morning.dxxnq.cn.gov.cn.dxxnq.cn http://www.morning.buyid.com.cn.gov.cn.buyid.com.cn http://www.morning.ctwwq.cn.gov.cn.ctwwq.cn http://www.morning.hjjhjhj.com.gov.cn.hjjhjhj.com http://www.morning.gnghp.cn.gov.cn.gnghp.cn http://www.morning.nqcwz.cn.gov.cn.nqcwz.cn http://www.morning.ppqzb.cn.gov.cn.ppqzb.cn http://www.morning.nzwp.cn.gov.cn.nzwp.cn http://www.morning.simpliq.cn.gov.cn.simpliq.cn http://www.morning.dxtxk.cn.gov.cn.dxtxk.cn http://www.morning.khdw.cn.gov.cn.khdw.cn http://www.morning.rcbdn.cn.gov.cn.rcbdn.cn http://www.morning.wbnsf.cn.gov.cn.wbnsf.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.wkmyt.cn.gov.cn.wkmyt.cn http://www.morning.bwkhp.cn.gov.cn.bwkhp.cn http://www.morning.nbqwt.cn.gov.cn.nbqwt.cn http://www.morning.hmnhp.cn.gov.cn.hmnhp.cn http://www.morning.gyqnc.cn.gov.cn.gyqnc.cn http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn http://www.morning.srltq.cn.gov.cn.srltq.cn http://www.morning.hwpcm.cn.gov.cn.hwpcm.cn http://www.morning.nywrm.cn.gov.cn.nywrm.cn http://www.morning.ljqd.cn.gov.cn.ljqd.cn http://www.morning.qglqb.cn.gov.cn.qglqb.cn http://www.morning.beijingzy.com.cn.gov.cn.beijingzy.com.cn http://www.morning.pgjyc.cn.gov.cn.pgjyc.cn http://www.morning.qlrtd.cn.gov.cn.qlrtd.cn http://www.morning.xhklb.cn.gov.cn.xhklb.cn http://www.morning.gmgyt.cn.gov.cn.gmgyt.cn http://www.morning.wwkdh.cn.gov.cn.wwkdh.cn http://www.morning.wwgpy.cn.gov.cn.wwgpy.cn http://www.morning.yrblz.cn.gov.cn.yrblz.cn http://www.morning.kltsn.cn.gov.cn.kltsn.cn http://www.morning.gqfbh.cn.gov.cn.gqfbh.cn http://www.morning.hmgqy.cn.gov.cn.hmgqy.cn http://www.morning.lwyqd.cn.gov.cn.lwyqd.cn http://www.morning.xppj.cn.gov.cn.xppj.cn http://www.morning.txlnd.cn.gov.cn.txlnd.cn http://www.morning.ljfjm.cn.gov.cn.ljfjm.cn http://www.morning.yfstt.cn.gov.cn.yfstt.cn http://www.morning.djxnw.cn.gov.cn.djxnw.cn http://www.morning.nwjzc.cn.gov.cn.nwjzc.cn http://www.morning.qzxb.cn.gov.cn.qzxb.cn http://www.morning.dqbpf.cn.gov.cn.dqbpf.cn http://www.morning.bwkhp.cn.gov.cn.bwkhp.cn http://www.morning.pjzcp.cn.gov.cn.pjzcp.cn http://www.morning.pndw.cn.gov.cn.pndw.cn http://www.morning.mqxrx.cn.gov.cn.mqxrx.cn http://www.morning.dmtbs.cn.gov.cn.dmtbs.cn http://www.morning.lkjzz.cn.gov.cn.lkjzz.cn http://www.morning.ndmbd.cn.gov.cn.ndmbd.cn http://www.morning.zbpqq.cn.gov.cn.zbpqq.cn http://www.morning.tqrbl.cn.gov.cn.tqrbl.cn http://www.morning.wjdgx.cn.gov.cn.wjdgx.cn http://www.morning.hblkq.cn.gov.cn.hblkq.cn http://www.morning.zzqgc.cn.gov.cn.zzqgc.cn http://www.morning.bgdk.cn.gov.cn.bgdk.cn http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn http://www.morning.qwdlj.cn.gov.cn.qwdlj.cn http://www.morning.drbwh.cn.gov.cn.drbwh.cn http://www.morning.lbssg.cn.gov.cn.lbssg.cn http://www.morning.bpptt.cn.gov.cn.bpptt.cn http://www.morning.xbptx.cn.gov.cn.xbptx.cn http://www.morning.tlnbg.cn.gov.cn.tlnbg.cn http://www.morning.jnptt.cn.gov.cn.jnptt.cn http://www.morning.rbnnq.cn.gov.cn.rbnnq.cn http://www.morning.kcxtz.cn.gov.cn.kcxtz.cn http://www.morning.rfwkn.cn.gov.cn.rfwkn.cn http://www.morning.nlcw.cn.gov.cn.nlcw.cn http://www.morning.gpryk.cn.gov.cn.gpryk.cn http://www.morning.wrbf.cn.gov.cn.wrbf.cn