Description
有n(2≤n≤20)块芯片,有好有坏,已知好芯片比坏芯片多。
每个芯片都能用来测试其他芯片。用好芯片测试其他芯片时,能正确给出被测试芯片是好还是坏。而用坏芯片测试其他芯片时,会随机给出好或是坏的测试结果(即此结果与被测试芯片实际的好坏无关)。
给出所有芯片的测试结果,问哪些芯片是好芯片。
每个芯片都能用来测试其他芯片。用好芯片测试其他芯片时,能正确给出被测试芯片是好还是坏。而用坏芯片测试其他芯片时,会随机给出好或是坏的测试结果(即此结果与被测试芯片实际的好坏无关)。
给出所有芯片的测试结果,问哪些芯片是好芯片。
Input
输入数据第一行为一个整数n,表示芯片个数。
第二行到第n+1行为n*n的一张表,每行n个数据。表中的每个数据为0或1,在这n行中的第i行第j列(1≤i, j≤n)的数据表示用第i块芯片测试第j块芯片时得到的测试结果,1表示好,0表示坏,i=j时一律为1(并不表示该芯片对本身的测试结果。芯片不能对本身进行测试)。
第二行到第n+1行为n*n的一张表,每行n个数据。表中的每个数据为0或1,在这n行中的第i行第j列(1≤i, j≤n)的数据表示用第i块芯片测试第j块芯片时得到的测试结果,1表示好,0表示坏,i=j时一律为1(并不表示该芯片对本身的测试结果。芯片不能对本身进行测试)。
Output
按从小到大的顺序输出所有好芯片的编号
Sample Input
3 1 0 1 0 1 0 1 0 1
Sample Output
1 3
已知好芯片比坏芯片多,因此测试为好次数最多的芯片必是好芯片
找出被测试为好次数最多的芯片,此芯片的测试数据必准确,输出此芯片的测试数据即可。
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 #include <math.h> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <set> 11 #include <map> 12 #include <sstream> 13 const int INF=0x3f3f3f3f; 14 typedef long long LL; 15 const double eps =1e-8; 16 const int mod=1e9+7; 17 const int maxn=1e6+10; 18 using namespace std; 19 20 int G[25][25]; 21 22 int main() 23 { 24 #ifdef DEBUG 25 freopen("sample.txt","r",stdin); 26 #endif 27 28 int n; 29 scanf("%d",&n); 30 for(int i=1;i<=n;i++) 31 { 32 for(int j=1;j<=n;j++) 33 scanf("%d",&G[i][j]); 34 } 35 int id; 36 int MAX=0; 37 for(int i=1;i<=n;i++) 38 { 39 int num=0; 40 for(int j=1;j<=n;j++) 41 { 42 if(i!=j&&G[i][j]) num++; 43 } 44 if(num>MAX) 45 { 46 MAX=num; 47 id=i; 48 } 49 } 50 int flag=0; 51 for(int i=1;i<=n;i++) 52 { 53 if(G[id][i]) 54 { 55 printf(flag==0?"%d":" %d",i); 56 flag=1; 57 } 58 } 59 60 return 0; 61 }
-