//Link

  https://www.hackerrank.com/challenges/sherlock-and-squares

 from math import sqrt # 用什么,引什么,减少浪费和错误可能性

 def main():
t = int(raw_input())
for _ in range(t):
squares = 0
a, b = map(int, raw_input().strip().split(' '))
temp = int(sqrt(a)) # 设置temp的起始判断点
while temp ** 2 <= b: # 卡住上下边界
if temp ** 2 >= a:
squares += 1
temp += 1 print squares main()

学习

  抽象到本质后,开始反向思维

  反向思维:

    正向思维的话:

      每个数都需要开方,要是注意到Input的要求,会发现这个量可是相当大的

    反向:

      用a开方上沿儿的边界值开始,平方后测试值在不在[a,b]范围内,因为平方的上升速度是相当快的

Sherlock and Squares的更多相关文章

  1. [LeetCode] Word Squares 单词平方

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  2. 卡通图像变形算法(Moving Least Squares)附源码

    本文介绍一种利用移动最小二乘法来实现图像变形的方法,该方法由用户指定图像中的控制点,并通过拖拽控制点来驱动图像变形.假设p为原图像中控制点的位置,q为拖拽后控制点的位置,我们利用移动最小二乘法来为原图 ...

  3. Leetcode: Word Squares && Summary: Another Important Implementation of Trie(Retrieve all the words with a given Prefix)

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  4. [LintCode] Perfect Squares 完全平方数

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  5. HDU 1264 Counting Squares(线段树求面积的并)

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. RSS(Residual Sum of Squares)的自由度为什么是n-1呢

    [转载请注明出处]http://www.cnblogs.com/mashiqi 在回归问题中,偶尔我们会遇到求方差的估计的情况.举了例子,我们常常通过Gaussian分布${\cal N}(\mu , ...

  7. poj-3739. Special Squares(二维前缀和)

    题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. ...

  8. [CareerCup] 7.5 A Line Cut Two Squares in Half 平均分割两个正方形的直线

    7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in ha ...

  9. POJ 2002 Squares

    二分.... Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 14530 Accepted: 5488 Descr ...

随机推荐

  1. css 画竖着线条

    <p>table控制:<!-- height为横线的粗度,width为长度 --><table width=700>     <tr>    <t ...

  2. QT creator中使用opencv

    最近要用到opencv做图像方面的东西,网上很多是用VS加opencv,但自己对VS不怎么喜欢,想用QT Creator.在网上搜索了很多资料,终于花了一天的时间,在QT Creator上能使用ope ...

  3. Windows平台的JDK安装(转)

    下载Java的开发包JDK JDK有好几个类型版本,我们只需要选择Java SE类型的版本就行了.进入网页:http://www.oracle.com/technetwork/java/javase/ ...

  4. bash模式和模式匹配

    bash模式和模式匹配 ${variable#pattern} 如果模式匹配变量取值的开头,删除最短匹配部分,返回其余部分 ${variable##pattern} 如果模式匹配变量取值的开头,删除最 ...

  5. T-SQL函数类别统计

  6. Raid1源代码分析--开篇总述

    前段时间由于一些事情耽搁了,最近将raid1方面的各流程整理了一遍.网上和书上,能找到关于MD下的raid1的文档资料比较少.决定开始写一个系列的关于raid1的博客,之前写过的一篇读流程也会在之后加 ...

  7. DL,DT,DD,比传统table更语义,解析更快的table列表方式

    使用dl,dt,dd替代传统的table布局 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...

  8. 查看syslog-ng内存,兼容容器情况

    syslog_pid=`ps -ef|grep syslog-ng|grep -v grep |awk '{print $2}'` pid_count=`ps -ef|grep syslog-ng|g ...

  9. Entify Framewrok - Join的使用方法

    问题:有2个表,使用id相连,如何用Join语法将其连接起来? 如下代码 List<tblAssociation> assoList = dataContext.tblAssociatio ...

  10. mongodb 更新数组出现can't append to array using string field name

    数据库内容大概如下: { _id:, "hero_list" : { " : { , , "equip" : [ [ ], [ ], [ ], { , ...