摘要:
Description现在有n个数,只有一个数出现奇数次,把它找出来。Input首先一个T表示有T组数据。每组数据一个n表示有(n<=100000)个数。接下来n个数字a0,a1……an-1( ai在int型范围内)。Output输出那个出现奇数次的数。Sample Input232 2 10000000051 2 2 2 2Sample Output1000000001分析:由于数据量比较大,不适合建立大的hash表来统计数据。相反利用异或运算的性质,1)可交换性 A XOR B XOR A = (A XOR A) XOR B2) 奇数次异或结果为本身,偶数次异或结果为0。 A XOR 阅读全文
随笔分类 - POJ 解题报告
POJ 2255 Tree Recovery解题报告
2011-10-24 15:30 by 诸葛二牛, 276 阅读, 收藏,
摘要:
刚开始以为是一个建立树的题目,后来一看就是用递归的思想来处理字符串。 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 /*核心函数。递归实现。 6 *preStr为先序遍历串,inStr为中序遍历串。 7 *假设preStr为“BCAD”,inStr为“CBAD”。 8 *则先找到根为”B“,根的左孩子为”C“,右孩子为”AD“。 9 *然后递归调用f,得到左孩子和右孩子的后序遍历串,再加上根即可。 10 */ 11 string f(string preStr, string . 阅读全文
POJ 2159 解题报告
2011-10-14 22:29 by 诸葛二牛, 293 阅读, 收藏,
摘要:
一、substitution cipher (置换密码):Substitution cipher changes all occurrences of each letter to some other letter.Substitutes for all letters must be different.For some letters substitute letter may coincide with the original letter. For example, applying substitution cipher that changes all letters from 阅读全文
浙公网安备 33010602011771号