当前位置:网站首页>001 chip test

001 chip test

2022-07-05 02:58:00 Hidden clouds and fog

Problem description

        Yes n(2≤n≤20) Chip chip , There are good and bad , We know that there are more good chips than bad ones .
   Each chip can be used to test other chips . When using the chip to test other chips , Whether the chip under test is good or bad can be given correctly . When testing other chips with bad chips , Will randomly give good or bad test results ( That is, this result has nothing to do with the actual quality of the chip being tested ).
   Give the test results of all chips , Ask which chips are good .

Input format

The first line of input data is an integer n, Number of chips .
   Line two to line two n+1 Behavior n*n A watch of , Each row n Data . Each data in the table is 0 or 1, Here n The first in the line i Xing di j Column (1≤i, j≤n) The data of is represented by No i Block chip test j The test results obtained when the chip is block ,1 Say good ,0 Means bad ,i=j All the time 1( It does not mean the test result of the chip on itself . The chip cannot test itself ).

Output format

Output all good chip numbers from small to large

The sample input

3
1 0 1
0 1 0
1 0 1

Sample output

1 3

Code

# Ideas : Because there are more good chips than bad ones , So when each chip is compared with other chips ,
# As long as the test result is greater than or equal to n/2 It can prove that this is a good chip , Then input the location of the chip .
#include<iostream>
#include<stdio.h>

using namespace std;

int a[100][100];

int main()
{
	int n;
	cin>>n;
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<n;j++)
		{
			cin>>a[i][j];
		}
	} 
	int b[100];
	for(int i=0;i<n;i++)
	{
		int sum = 0;
		for(int j = 0;j<n;j++)
		{
			if(a[j][i]==1)
                sum++; 
		}
		b[i] = sum;
	}
	for(int i = 0;i<n;i++)
	{
		
		if(b[i]-1>=n/2)
            cout<<i+1<<" ";
	}
	cout<<endl;
	return 0;
} 

原网站

版权声明
本文为[Hidden clouds and fog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140835053894.html