[Chip test questions basic exercises]

Problem Description
  There are n (2≤n≤20) chips, good and bad, are known better than the bad chip-chip .
  Each chip can be used to test other chips. Hershey with other chip test chip, can be given the right test chip is good or bad . But with bad chip testing other chips, random give good or bad test results (i.e., the result is independent of the actual test chip is good or bad).
  All test results are given chip, chip ask what is a good chip.
Input Format
  A first line data input integer n, the number of chips.
  The second row to n + 1 n * n behavior of a table, each row of n data. Each data table is 0 or 1, in this i-th row in the n-th row j-th column (1≤i, j≤n) data representing test results obtained by the i-th block of the j-chip test chips 1 represents good, bad 0 indicates, when I 1 = j is uniformly (the test result does not indicate that the chip itself. chip itself can not be tested).
Output Format
  In ascending order of the number of outputs of all the good chips
Sample input
3
1 0 1
0 1 0
1 0 1
Sample Output
1 3
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static  int v1,v2,t,s,L;
    static String ch;
    public  static  void main(String [] args){
        Scanner sc =new Scanner(System.in);
        int n = sc.nextInt();
        int arr[][] = new int[n][n];
        List <Integer> list = new ArrayList<Integer>();
        List <Integer> list1 = new ArrayList<Integer>();
        for(int i=0;i<n;i++)
            for (int j=0;j<n;j++)
                arr[i][j] = sc.nextInt();

        for(int i=0;i<n;i++){
            int x=0,y=0;
            for (int j=0;j<n;j++){
              if(arr[i][j]==1) {
                  list.add(j);
                  x++;
              }
              else y++;
            }
            if(x<=y) list.clear();///没有达到条件的,先清空
            if(x>y) break;
        }
                for(int i=0;i<n;i++){

                    boolean flag=true;
                    for(int j=0;j<list.size();j++)
                        if(arr[i][list.get(j)]==0){
                           flag=false;
                           break;
                        }
                        if(flag) list1.add(i+1);
                }


                for(int i=0;i<list1.size();i++) System.out.print(list1.get(i)+" ");
   }
}

  

Guess you like

Origin www.cnblogs.com/wszhu/p/12600121.html