蓝桥杯--芯片测试

http://47.104.209.207/problem/old1065

如果超过n/2的芯片测试i为正常,那么i就是正常的。

反证:如果i不是正常的话,那么至少n/2个芯片的测试结果是错误的,与条件相违背。

不漏性证明:即证明如果少于n/2个芯片说i正常,那么i不可能是正常的。

      从条件出发,至少有n/2个芯片是正常的,如果i是正常的,那么检测结果中至少会有n/2个结果说明i正常,与假设相违背。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 const int N=30;
 7 int a[N][N],cnt[N];
 8 int main()
 9 {
10     int n;
11     cin>>n;
12     for(int i=1;i<=n;i++){
13         for(int j=1;j<=n;j++){
14             int t;
15             cin>>t;
16             if(i!=j&&t==1){
17                 cnt[j]++;
18             }
19         }
20     }
21     for(int i=1;i<=n;i++){
22         if(cnt[i]>=n/2){
23             cout<<i<<" ";
24         }
25     }
26     return 0;
27 }
原文地址:https://www.cnblogs.com/greenofyu/p/14454366.html