HBC232720[JSOI2008]最小生成树计数,生成树,图论圣题解

把回忆走一遍 基本结构 67 0
全网最全C++题库,助您快速提升编程技能!题库丰富多样,涵盖各个领域,让您在练习中不断成长!

给定 nnn 个数 aia_iai​,求值:XORi=1nORj=1n(ai AND aj)text{XOR}_{i=1}^{n}text{OR}_{j=1}^{n}(a_i~text{AND}~a_j)XORi=1n​ORj=1n​(ai​ AND aj​),其中符号 XORi=1nai=(a1 XOR a2 ⋯ XOR an)text{XOR}_{i=1}^{n}a_i=(a_1~text{XOR}~a_2~cdots~text{XOR}~a_n)XORi=1n​ai​=(a1​ XOR a2​ ⋯ XOR an​),另外两个符号同理。 例如 n=2n=2n=2 时即计算:[(a1 AND a1) OR (a1 AND a2)]XOR[(a2 AND a1) OR(a2 AND a2)]left[(a_1~text{AND}~a_1)~text{OR}~(a_1~text{AND}~a_2)right]text{XOR}left[(a_2~text{AND}~a_1)~text{OR}(a_2~text{AND}~a_2)right][(a1​ AND a1​) OR (a1​ AND a2​)]XOR[(a2​ AND a1​) OR(a2​ AND a2​)] 的值。 (摘自 oiwiki) 伪代码:init() 读入,print() 输出 T ← init() for k ← 1 .. T     n ← init()     for i ← 1 .. n a[i] ← init()     ans ← 0     for i ← 1 .. n         tp ← 0         for j ← 1 .. n             tp ← tp or (a[i] and a[j])         ans ← ans xor tp     print(ans) C/C++ 语言版: for (k = 1; k <= T; ++k) { n = init(); for (i = 1; i <= n; ++i) a[i] = init(); ans = 0; for (i = 1; i <= n; ++i) { tp = 0; for (j = 1; j <= n; ++j) tp |= (a[i] & a[j]); ans ^= tp; } }

成为编程大师,不再是梦想!全网最全C++题库,助您开启编程新篇章。

标签: HBC232720[JSOI2008]最小生成树计数 生成树 图论圣题解