题目描述
http://acm.nyist.net/JudgeOnline/problem.php?pid=508
给你两个数n,k,请求出的值。
输入每行两个数n, k(1 输出输出和,每个结果占一行。样例输入
5 4
5 3
样例输出
5
7
题目分析:
对于此题不能直接进行暴力,数值大,只能用sqrt(n)的算法,首先计算n%i的余数和,i=1~n;注意...
分类:
其他好文 时间:
2015-01-07 20:57:57
阅读次数:
216
题目描述:
Implement int sqrt(int x).
Compute and return the square root of x.
思路分析:采用二分查找的思想。当未找到mid=x/mid时,若mid>x/mid,则表示mid-1为平方值最接近但不超过x的值,即结果为mid-1。若mid
代码:
if(x == 0 || x == 1)
...
分类:
其他好文 时间:
2015-01-07 20:57:12
阅读次数:
143
在以往判断一个数n是不是素数时,我们都是采用i从2到sqrt(n)能否整除n.如果能整除,则n是合数;否则是素数.但是该算法的时间复杂度为O(sqrt(n)),当n较大时,时间性能很差,特别是在网络安全和密码学上一般都是需要很大的素数.而从目前来看,确定性算法判断素数的性能都不好,所以可以用MC概率...
分类:
编程语言 时间:
2015-01-06 13:44:33
阅读次数:
408
The problem:Implementint sqrt(int x).Compute and return the square root ofx.My analysis:The problem could be solved amazingly by using binary search.W...
分类:
其他好文 时间:
2015-01-06 01:59:20
阅读次数:
219
https://oj.leetcode.com/problems/sqrtx/http://blog.csdn.net/linhuanmars/article/details/20089131publicclassSolution{
publicintsqrt(intx){
//Assumex>=0
if(x==0)
return0;
returns(x,0L,(long)x);
}
privateintcalc(intx,longlow,longhigh)
{
//Whyusinglong.
/..
分类:
其他好文 时间:
2015-01-04 19:44:12
阅读次数:
143
转自:http://www.cnblogs.com/pkuoliver/archive/2010/10/06/sotry-about-sqrt.html源码下载地址:http://diducoder.com/sotry-about-sqrt.html好吧,我承认我标题党了,不过既然你来了,就认真看下...
分类:
其他好文 时间:
2015-01-03 17:15:03
阅读次数:
136
Sqrt(x)Implementint sqrt(int x).Compute and return the square root ofx.SOLUTION 1:参见:二分法总结,以及模板:http://t.cn/RZGkPQc 1 public class Solution { 2 pu...
分类:
其他好文 时间:
2015-01-02 23:35:53
阅读次数:
184
一道计算几何裸题。。。调了蒟蒻两个小时。。。问题出在求dis的时候忘了sqrt了,好了你现在可以退役滚蛋了,简直侮辱我们搞OI的人的智商首先求个凸包出来,矩形的一边一定和凸包上一边重合。然后枚举凸包上的边,用三个点同时旋转卡壳,卡出最小的矩形。这题目写的我。。。醉了 1 /************....
分类:
其他好文 时间:
2015-01-01 22:24:40
阅读次数:
377
bool prime(long n){ for(long i=2;i<=sqrt(n);i++){ if(n%i== 0){ return false; } } return true;}复杂度O(n*sqrt(n))如想要...
分类:
其他好文 时间:
2015-01-01 08:58:33
阅读次数:
122
题目大意
有n个数,m个查询,对于每个查询,询问指定区间,有多少个数对的绝对值小于等于2。
解题思路
莫队O^1.5
首先将询问离线处理左端点进行编号,每sqrt(n)个为一组
sort结构体 当左端点编号相同时,比较右端点大小。小的放在前面。
对于每组询问暴力处理,只需处理当前新加入(删除的数字在当前区间内有多少点和它的绝对值只差小于2即可)
唯一要注意的是加点是...
分类:
编程语言 时间:
2014-12-31 20:15:07
阅读次数:
283