Chip test

1. Write in front

Drawer principle:

  There are ten apples on the table. Put these ten apples into nine drawers. No matter how you put them, we will find at least one drawer with at least two apples in it. This phenomenon is what we call the "drawer principle". The general meaning of the drawer principle is: "If each drawer represents a set, and each apple can represent an element, if there are n+1 elements placed in n sets, there must be at least two sets in one set. Elements." The drawer principle is also sometimes referred to as the pigeonhole principle. It is an important principle in combinatorics.

The first drawer principle

Principle 1: Put more than n+1 objects into n drawers, then at least one drawer contains no less than two items.

 

Proof (evidence by contradiction): If each drawer can only put at most one object, then the total number of objects is at most n×1, not n+k (k≥1) of the title, so it is impossible.

Principle 2: Put more than mn(m times n)+1 (n is not 0) objects into n drawers, then at least one drawer has no less than (m+1) objects.

Proof (evidence by contradiction): If each drawer can put at most m objects, then n drawers can put at most mn objects, which is inconsistent with the title, so it is impossible.

Principle 3: Put an infinite number of objects into n drawers, then at least one drawer has an infinite number of objects.

Principles 1, 2, and 3 are all expressions of the first drawer principle.

The second drawer principle

Put (mn-1) objects into n drawers, one of which must have at most (m-1) objects (for example, put 3×5-1=14 objects into 5 drawers, Then there must be a drawer with less than or equal to 3-1=2).

 

2. 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 testing other chips with a good chip, it can correctly show whether the tested chip is good or bad. When testing other chips with a bad chip, it will randomly give a good or bad test result (that is, the result has nothing to do with the actual quality of the tested chip).
  Given the test results of all chips, ask which chips are good chips.

3. Input format

  The first line of the 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, and each row has n data. Each data in the table is 0 or 1, and the data in the i-th row and the j-th column (1≤i, j≤n) in the 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, when i=j, it is always 1 (it does not mean the test result of the chip itself. The chip cannot test itself).

4. Output format

  Output the numbers of all good chips in ascending order

sample input

3
1 0 1
0 1 0
1 0 1

5. Sample output

1 3

 

Sixth, the problem idea:

In any even number of chips, if there are more good chips than bad chips, all chips are grouped in pairs. According to the drawer principle, there are
1) There must be two good chips in a group.
2) The number of groups of the same good chips must be more than the number of groups of the same bad chips.

When the value of Cout is greater than or equal to n/2, it is a good chip, and it cannot test itself.

Seven, the code part

 

 1 #include<stdio.h>
 2 int a[20][20];
 3 int main()
 4 {
 5     int n,ans;
 6     int i,j;
 7     scanf("%d",&n);
 8 
 9     for(i=0; i<n; i++)
10     {
11         for(j=0; j<n; j++)
12         {
13             scanf("%d",&a[i][j]);
14         }
15     }
16     for(i=0; i<n; i++)
17     {
18         ans=0;
19         for(j=0; j<n; j++)
20         {
21             if(i!=j)
22                 ans+=a[j][i];
23         }
24         if(ans>=n/2)
25         {
26             printf("%d ",i+1);
27         }
28     }
29     return 0;
30 }

 

 

 

 

 参考链接:[1]https://baike.baidu.com/item/%E6%8A%BD%E5%B1%89%E5%8E%9F%E7%90%86/233776?fr=aladdin

[2]https://blog.csdn.net/jyl1159131237/article/details/78630761

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325338828&siteId=291194637