Resource limit
Time limit: 1.0s Memory limit: 512.0MB
Problem Description
There are n (2≤n≤20) chips, good or bad. It is known that there are more good chips than bad ones. Each chip can be used to test other chips. When testing other chips with a good chip, it can correctly give out whether the tested chip is good or bad. When using a bad chip to test other chips, it will randomly give good or bad test results (that is, this result has nothing to do with the actual quality of the tested chip). Give the test results of all chips and ask which chips are good chips.
The first line of input data is an integer n, indicating the number of chips. The second row to the n + 1th row are n * n tables with n data in each row. Each data in the table is 0 or 1. The data in the i-th row and j-th column (1≤i, j≤n) in the n-rows represents the test results obtained when testing the j-th chip with the i-th chip , 1 means good, 0 means bad, when i = j, it will always be 1 (does not mean the test result of the chip on itself. The chip cannot test itself).
Output format
Output the numbers of all good chips in order from small to large
Sample input
3 1 0 1 0 1 0 1 0 1
Sample output
1 3
Code
1 import java.util.Scanner; 2 import java.util.*; 3 4 5 public class Main { 6 static int n,a[][],count[]; 7 8 public static void main(String[] args) { 9 Scanner sc = new Scanner(System.in); 10 n = sc.nextInt(); 11 a = new int[22][22]; 12 count = new int [25]; 13 for(int i=1;i<=n;i++){ 14 for(int j=1;j<=n;j++){ 15 a[i][j] = sc.nextInt(); 16 } 17 } 18 19 for(int i=1;i<=n;i++){ 20 for(int j=1;j<=n;j++){ 21 if(i!=j&&a[i][j]==1) 22 count[j]++; 23 } 24 } 25 for(int j=1;j<=n;j++) 26 if(count[j]>=n/2) 27 System.out.print(j + " "); 28 } 29 30 }