poj 2419

    技术2022-05-13  0

     

    Forests Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4863 Accepted: 1826

    Description

    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 4

    Sample Output

    2

    Source

    Waterloo Local 2002.01.26 刷了才知道是水题,哎。。。。 #include <iostream> using namespace std; int g[101][101]; bool comp(int x,int y) { for(int i=1;i<101;++i) if(g[x][i]!=g[y][i])return false; return true; } int main() { //freopen("car.in","r",stdin); //freopen("car.out","w",stdout); int p,t,i,j; scanf("%d%d",&p,&t); memset(g,0,sizeof(g)); while(scanf("%d%d",&i,&j)!=EOF)g[i][j]=true; for(i=0;i<=p;++i)g[i][0]=i; for(i=1;i<p;++i) for(j=i+1;j<=p;++j) if(comp(i,j))g[j][0]=g[i][0]; int m[101]={0},ans=0; for(i=1;i<=p;++i) if(!m[g[i][0]]) { m[g[i][0]]=true; ++ans; } printf("%d/n",ans); return 0; }  

     


    最新回复(0)