题目链接:
https://cn.vjudge.net/problem/POJ-2419
题目描述:
If a tree falls in the forest, and there's nobody there to hear, does it make a sound? This classic conundrum was coined by George Berkeley (1685-1753), the Bishop and influential Irish philosopher whose primary philosophical achievement is the advancement of what has come to be called subjective idealism. He wrote a number of works, of which the most widely-read are Treatise Concerning the Principles of Human Knowledge (1710) and Three Dialogues between Hylas and Philonous (1713) (Philonous, the "lover of the mind," representing Berkeley himself).
Input
A forest contains T trees numbered from 1 to T and P people numbered from 1 to P. Standard input consists of a line containing P and T followed by several lines, containing a pair of integers i and j, indicating that person i has heard tree j fall.
Output
People may have different opinions as to which trees, according to Berkeley, have made a sound. Output how many different opinions are represented in the input? Two people hold the same opinion only if they hear exactly the same set of trees. You may assume that P < 100 and T < 100.
Sample Input
3 4 1 2 3 3 1 3 2 2 3 2 2 4Sample Output
2
1 /* 2 题意描述 3 有p个人去听t棵树倒下的声音,问有几种不同的观点数 4 5 解题思路 6 用二维数组记录i听到j倒下,如果某个人听到的结果和另一个完全相同,说明这两个人是一种观点,需要总观点数减一 7 */ 8 #include<cstdio> 9 #include<cstring> 10 const int maxn=100+10; 11 12 bool g[maxn][maxn]; 13 int t,p; 14 int common(int a,int b); 15 16 int main() 17 { 18 int x,y; 19 memset(g,0,sizeof(bool)*maxn*maxn); 20 scanf("%d%d",&p,&t); 21 while(scanf("%d%d",&x,&y) != EOF){ 22 g[x][y]=1; 23 } 24 int sum=p; 25 for(int i=1;i<=p-1;i++){ 26 for(int j=i+1;j<=p;j++){ 27 if(common(i,j)){ 28 sum--; 29 break;//遇到一个重复以后,总观点数减1后直接判断下一个 30 } 31 } 32 } 33 printf("%d ",sum); 34 return 0; 35 } 36 37 int common(int a,int b) 38 { 39 for(int i=1;i<=t;i++){ 40 if(g[a][i] != g[b][i]) 41 return 0; 42 } 43 return 1; 44 }