摘要:题目大意: 一共有n个学生(编号0 至 n-1),m个组,一个学生可以同时加入不同的组。现在有一种传染病,如果一个学生被感染,那么和他同组的学生都会被感染。现在已知0号学生被感染,问一共有多少个人被感染。思路:刚开始我想,先输入将他们合并入一个集合m,如果遇到0则将所有的放入0这个集合,再查找。总之很难实现。 看了代码后,才发现别人思路的高明之处:一边输入,一边合并,最后输出b[0]即可。代码:#include<stdio.h>short a[30000],b[30000];int f(int i){ if(a[i]==i) return i; return a[i]=f(a[i]
阅读全文
摘要:A very big corporation is developing its corporative network. In the beginning each of the N enterprises of the corporation, numerated from 1 to N, organized its own computing and telecommunication center. Soon, for amelioration of the services, the corporation started to collect some enterprises in
阅读全文
摘要:There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university believe in.You know that there are n students in your university (0< n<= 50000). It is infeasible
阅读全文
摘要:描述约翰和贝西在玩叠积木的游戏。共有N(1 ≤ N ≤ 30000)块积木,分别编号为1到N。起初,他们把这些积木平放在地上,自然地分成N堆,每堆只有一块。 积木之间可以相互堆叠,最后会越叠越高。约翰让贝西执行P(1 ≤ P ≤ 100000)条命令,命令可以分为两种类型:移动命令:贝西需要取出包含X的那堆积木,将它们完整地叠放到包含Y的那堆积木之上;计数命令:贝西需要报告当前在编号为Z的积木之下压有多少块积木请编写一个程序,帮助贝西输出正确的答案。输入第一行:单个整数:P第二行到第P + 1行:每行描述了一条命令,保证所有的命令都是合法的。如果这行开头的字母是 M,代表一条移动命令,后面的两
阅读全文