VIP test questions basic practice chip test (finding rules, statistics)

Resource limit

Time limit: 1.0s Memory limit: 512.0MB

Problem Description

  There are n (2≤n≤20) chips, both good and bad. It is known that there are more good chips than bad chips.
  Each chip can be used to test other chips. When using a good chip to test other chips, it can correctly tell whether the tested chip is good or bad. When using a bad chip to test other chips, it will randomly give a good or bad test result (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 ones.

Input format

  The first line of input data is an integer n, which represents the number of chips.
  The second row to the n+1th row is a table of n*n 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 these n rows represents the test result obtained when the i-th chip is used to test the j-th chip , 1 means good, 0 means bad, and it is always 1 when i=j (it does not mean the test result of the chip on itself. The chip cannot test on itself).

Output format

  Output the numbers of all good chips in ascending order

Sample input

3
1 0 1
0 1 0
1 0 1

Sample output

1 3

 Ideas:

From the question "There are more known good chips than bad chips." It can be deduced: When a good chip is judged by others: the number of 0 in it will be less than the number of 1. Relatively bad chips are judged by others: the number of ones in it will be less than the number of zeros.

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int i,j;
	int a[21][21];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	for(j=1;j<=n;j++)
	{
		scanf("%d",&a[i][j]);
	}//输入数据 
	int f=0;
	for(j=1;j<=n;j++)
	{
		int sum1=0,sum0=0;
		for(i=1;i<=n;i++)
		{
			if(a[i][j]==1)
			sum1++;
			else
			sum0++;
		}
		if(sum1>sum0)
		{
			if(f==0)
			{
				printf("%d",j);
				f=1;
			}
			else
			printf(" %d",j);
		}
	}
	return 0;
}

 

Guess you like

Origin blog.csdn.net/with_wine/article/details/115023022