上一页 1 2 3 4 5 6 7 8 9 ··· 13 下一页
摘要: 题目地址:http://poj.org/problem?id=2785 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #i... 阅读全文
posted @ 2015-03-22 20:00 SXISZERO 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 题目地址:http://poj.org/problem?id=3320 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #i... 阅读全文
posted @ 2015-03-21 21:40 SXISZERO 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 题目地址:http://poj.org/problem?id=3061方法一:因为元素都大于0,所以维护前缀和sum[i],一定有sum[k]>sum[i](k>i)。这样子序列起点s确定以后,用二分查找确定使序列和不小于s的结尾t的最小值。 时间复杂度o(nlogn)。 1 #include... 阅读全文
posted @ 2015-03-21 10:14 SXISZERO 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 有n个物品的重量和价值分别是wi和vi。从中选出k个物品使得单位重量的价值最大。 1 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #inclu... 阅读全文
posted @ 2015-03-20 20:35 SXISZERO 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 题目地址:http://poj.org/problem?id=2456最大化最小值问题。二分牛之间的间距,然后验证。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #... 阅读全文
posted @ 2015-03-20 09:59 SXISZERO 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 题目地址:http://poj.org/problem?id=1064有N条绳子,它们的长度分别为Ai,如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长。二分绳子长度,然后验证即可。复杂度o(nlogm) 1 #include 2 #include 3 #include 4 #inc... 阅读全文
posted @ 2015-03-19 16:29 SXISZERO 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 时间复杂度o(nlogn)。STL中为lower_bound,upper_bound。 1 int bin_search(int *a,int h,int t,int k) 2 { 3 int lb=h-1,ub=t; 4 5 while(ub-lb>1) { 6 ... 阅读全文
posted @ 2015-03-19 16:24 SXISZERO 阅读(145) 评论(0) 推荐(0) 编辑
摘要: i的二进制的最后一个1可以通过i&(-i)得到,时间复杂度o(logn)。对于W*H的二维BIT只需要建立H个大小为x轴方向元素个数W的BIT,复杂度O(logW+logH)。同样的方法可以扩展到更高维度的情况。 1 int sum(int i) 2 { 3 int s=0; 4 w... 阅读全文
posted @ 2015-03-18 22:33 SXISZERO 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 1.素性测试//素性测试o(sqrt(n))1 int is_prime(int n)2 {3 for(int i=2;i*i divisor(int n) { 2 vector res; 3 for(int i=2;i*i prime_factor(int n) 2 {... 阅读全文
posted @ 2015-03-17 16:33 SXISZERO 阅读(241) 评论(0) 推荐(0) 编辑
摘要: 转自网上大牛博客,讲的浅显易懂。原文地址:http://www.cnblogs.com/frog112111/archive/2012/08/19/2646012.html欧几里德算法欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数。基本算法:设a=qb+r,其中a,b,q,r都是整数... 阅读全文
posted @ 2015-03-14 22:59 SXISZERO 阅读(196) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 13 下一页