摘要: 题意:求n个非负数中任意2个的异或值的最大值。n数量级为10^5分析:直接暴力肯定超时了。一个非负整数可以看成1个32位的01字符串,n个数可以看成n个字符串,因此可以建立字典树,建好树后,对于任意非负整数x,可以沿着树根往下贪心找到y,使得x异或y最大,复杂度为树的深度。View Code #include <stdio.h>#include <string.h>#define MAX(a,b) ((a)>(b)?(a):(b))#define NODE 3200010#define N 100010int n;int v[N];int node;int nex 阅读全文
posted @ 2012-07-22 23:39 BeatLJ 阅读(3437) 评论(0) 推荐(0) 编辑
摘要: 题目大意:找出1到300的数中其平方在b进制下是回文的数,并打印这些数数及其平方在b进制下的表示。View Code /*ID: lijian42LANG: C++TASK: palsquare*/#include <stdio.h>#define LEN 20#define N 300char t[20]={'0','1','2','3','4','5','6','7','8','9','A','B 阅读全文
posted @ 2012-07-22 21:22 BeatLJ 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 题目大意:2到9每个数字对应3字母(对应关系题中已给出),给定一个长度不超过12的数字序列,则可以对应到多个字符串,现给定一个字典(含很多字符串的文件),打印数字序列对应的且在字典中出现过的字符串。分析:每个数字对应3个字母,最坏情况下有12个数字,可对应312=531441个字符串,而且题中字典中的字符串是按字典序给出的,所以可以用二分查找,所以应该可以用暴力+二分过。另一个办法就是建字典树,然后dfs时边搜遍判断,这样效率应该有所提升。我是用字典树过的。需要注意的是当字典中不存在符合要求的字符串时,要输出“NONE”View Code /*ID: lijian42LANG: C++TASK 阅读全文
posted @ 2012-07-22 20:49 BeatLJ 阅读(305) 评论(1) 推荐(0) 编辑
摘要: DescriptionIn this problem, you are given a pair of integers A and B. You can transform any integer number A to B by adding x to A.This x is an integer number which is a prime below A.Now,your task is to find the minimum number of transformation required to transform S to another integer number T.In 阅读全文
posted @ 2012-07-22 19:31 BeatLJ 阅读(350) 评论(0) 推荐(0) 编辑