2013年2月5日

XOJ Divisor counting

摘要: Divisor countingLetσ(n)denote the number of divisors ofn.Computeσ(1)+σ(2)+⋯+σ(n).InputAn integern.(1≤n≤10^14)OutputThe sum.Sample input5Sample output10直接枚举,枚举技巧:只要枚举到sqrt(n),另一半可以根据(n/i+n/(i+1))*i得出。。View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namesp 阅读全文

posted @ 2013-02-05 20:37 acoderworld 阅读(73) 评论(0) 推荐(0)

XOJ Square free

摘要: Square freeTest whethernis square free.nis square free if and only if for allp>1,p2is not divisors ofn.InputThe first line contains an integert, the number of test cases.The followingnlines, each contains an integern.(1≤t≤10^2,1≤n≤10^18)OutputPrint "Yes" ifnis square free, or "No&q 阅读全文

posted @ 2013-02-05 20:34 acoderworld 阅读(73) 评论(0) 推荐(0)

XOJ 拓扑排序

摘要: Topological sortingFind the lexicographicalally smallest topological sorting of given directed acyclic graphG.InputThe first line containsn,m, which denote the number of vertices and edges.The followingmlines containai,bi, which denote edgeai→bi.(1≤n≤105^,0≤m≤10^6,1≤ai,bi≤n)Outputnintegers denotes t 阅读全文

posted @ 2013-02-05 20:22 acoderworld 阅读(112) 评论(0) 推荐(0)

HDU 2846--字典树

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2846题意是给出一些模式串,再给出几个询问,询问给出的字符串在多少个模式串中出现比如字符串abc所含的字串有a,ab,abc,b,bc,c可用字典树解决,字典树能很好的处理前缀出现的次数,所以可将模式串分解,依次插入需要注意的是对于同一个模式串的不同子串可能有相同的前缀,为了避免多次计算,可以添加字典树节点的信息,添加num记录最后插入的字符串是第num个模式串的子串。关键在于怎么控制避免多次计算。。。在写的时候脑残的先计数然后在进行移位,应该要反过来。。。 1 #include<iostream> 阅读全文

posted @ 2013-02-05 16:10 acoderworld 阅读(72) 评论(0) 推荐(0)

HDU 1075--字典树

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1075字典树,就是输入的字符处理比较恶心,还有应该注意的是避免前缀问题。。如:字典里有liwo,但是查找liw的时候应该是找不到的,不能单从NULL判断有没有找到,还要看那个节点是否有存字符串。。代码: 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 struct node{ 6 char a[25]; 7 node *next[26]; 8 node( 阅读全文

posted @ 2013-02-05 14:35 acoderworld 阅读(146) 评论(0) 推荐(0)

导航